/* Reset and Base Styles */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Alpine.js cloak - hide elements until Alpine initializes */
[x-cloak] { display: none !important; }

/* ========== Custom Scrollbars ========== */

/* Scrollbar variables */
:root {
    --scrollbar-width: 10px;
    --scrollbar-width-thin: 6px;
    --scrollbar-track: var(--color-bg-secondary);
    --scrollbar-thumb: var(--color-text-secondary);
    --scrollbar-thumb-hover: var(--color-text-primary);
    --scrollbar-radius: 5px;
}

/* Firefox scrollbar styling */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

/* WebKit scrollbar styling (Chrome, Safari, Edge) */
::-webkit-scrollbar {
    width: var(--scrollbar-width);
    height: var(--scrollbar-width);
}

::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
    border-radius: var(--scrollbar-radius);
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: var(--scrollbar-radius);
    border: 2px solid var(--scrollbar-track);
    background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
    border: 2px solid var(--scrollbar-track);
    background-clip: padding-box;
}

::-webkit-scrollbar-corner {
    background: var(--scrollbar-track);
}

/* Thin scrollbars for smaller containers */
.thin-scrollbar,
.modal-content,
.page-link-results,
.inline-autocomplete,
.emoji-dropdown,
.editor-textarea,
.preview-content {
    scrollbar-width: thin;
}

.thin-scrollbar::-webkit-scrollbar,
.modal-content::-webkit-scrollbar,
.page-link-results::-webkit-scrollbar,
.inline-autocomplete::-webkit-scrollbar,
.emoji-dropdown::-webkit-scrollbar,
.editor-textarea::-webkit-scrollbar,
.preview-content::-webkit-scrollbar {
    width: var(--scrollbar-width-thin);
    height: var(--scrollbar-width-thin);
}

.thin-scrollbar::-webkit-scrollbar-thumb,
.modal-content::-webkit-scrollbar-thumb,
.page-link-results::-webkit-scrollbar-thumb,
.inline-autocomplete::-webkit-scrollbar-thumb,
.emoji-dropdown::-webkit-scrollbar-thumb,
.editor-textarea::-webkit-scrollbar-thumb,
.preview-content::-webkit-scrollbar-thumb {
    border-width: 1px;
}

/* Hide scrollbar until hover for cleaner look */
.scrollbar-on-hover {
    scrollbar-width: none;
}

.scrollbar-on-hover::-webkit-scrollbar {
    width: 0;
    height: 0;
}

.scrollbar-on-hover:hover {
    scrollbar-width: thin;
}

.scrollbar-on-hover:hover::-webkit-scrollbar {
    width: var(--scrollbar-width-thin);
    height: var(--scrollbar-width-thin);
}

html {
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--color-bg-primary);
    color: var(--color-text-primary);
    min-height: 100vh;
}

a {
    color: var(--color-accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

img {
    max-width: 100%;
    height: auto;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.25;
    margin-bottom: var(--spacing-sm);
    color: var(--color-text-primary);
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.125rem; }

p {
    margin-bottom: var(--spacing-md);
}

/* Layout */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--spacing-md);
}

.main-content {
    padding: var(--spacing-md) 0;
    min-height: calc(100vh - 64px);
}

/* Navbar */
.navbar {
    background-color: var(--color-bg-secondary);
    border-bottom: 1px solid var(--color-border);
    height: 64px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 var(--spacing-md);
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-lg);
}

.navbar-brand {
    flex-shrink: 0;
}

.navbar-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--color-accent));
}

.navbar-logo:hover {
    text-decoration: none;
    color: var(--color-accent-light);
}

.navbar-logo-img {
    height: 32px;
    width: auto;
    object-fit: contain;
}

.navbar-search {
    flex: 1;
    max-width: 400px;
}

.search-input {
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-md);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background-color: var(--color-bg-primary);
    color: var(--color-text-primary);
    font-size: 0.875rem;
}

.search-input:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px var(--color-accent-alpha);
}

.search-input:focus + .search-shortcut {
    opacity: 0;
}

/* Search Wrapper & Autocomplete */
.search-wrapper {
    position: relative;
}

.search-shortcut {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    gap: 2px;
    pointer-events: none;
    opacity: 0.5;
    transition: opacity 0.15s;
}

.search-shortcut kbd {
    font-family: inherit;
    font-size: 0.65rem;
    padding: 2px 4px;
    background: var(--color-bg-tertiary);
    border: 1px solid var(--color-border);
    border-radius: 3px;
    color: var(--color-text-secondary);
}

.search-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    max-height: 400px;
    overflow-y: auto;
    z-index: 1000;
}

.search-loading,
.search-empty,
.search-hint {
    padding: var(--spacing-md);
    text-align: center;
    color: var(--color-text-secondary);
    font-size: 0.875rem;
}

.search-result-item {
    display: flex;
    align-items: flex-start;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    text-decoration: none;
    color: inherit;
    transition: background-color 0.1s;
}

.search-result-item:hover,
.search-result-item.selected {
    background-color: var(--color-bg-secondary);
}

.search-result-icon {
    font-size: 1.25rem;
    line-height: 1;
    flex-shrink: 0;
    margin-top: 2px;
}

.search-result-content {
    flex: 1;
    min-width: 0;
}

.search-result-title {
    font-weight: 500;
    color: var(--color-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
}

.search-result-badge {
    font-size: 0.65rem;
    padding: 1px 4px;
    background: var(--color-warning-alpha, rgba(245, 158, 11, 0.15));
    color: var(--color-warning);
    border-radius: 3px;
    text-transform: uppercase;
    font-weight: 600;
    flex-shrink: 0;
}

.search-result-meta {
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    display: flex;
    gap: var(--spacing-sm);
    margin-top: 2px;
}

.search-result-category {
    background: var(--color-accent-alpha);
    color: var(--color-accent);
    padding: 1px 6px;
    border-radius: 3px;
    font-weight: 500;
}

.search-result-path {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-view-all {
    display: block;
    padding: var(--spacing-sm) var(--spacing-md);
    text-align: center;
    font-size: 0.875rem;
    color: var(--color-accent);
    border-top: 1px solid var(--color-border);
    text-decoration: none;
}

.search-view-all:hover {
    background: var(--color-bg-secondary);
}

.navbar-menu {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.navbar-link {
    color: var(--color-text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
}

.navbar-link:hover {
    color: var(--color-accent);
    text-decoration: none;
}

/* User Menu */
.user-menu {
    position: relative;
}

.user-menu-toggle {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-xs) var(--spacing-sm);
    background: none;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--color-text-primary);
}

.user-menu-toggle:hover {
    background-color: var(--color-bg-secondary);
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: var(--color-accent);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
}

.user-name {
    font-size: 0.875rem;
    font-weight: 500;
}

.user-role {
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 3px;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.user-role-admin {
    background-color: var(--color-danger-alpha, rgba(239, 68, 68, 0.15));
    color: var(--color-danger);
}

.user-role-editor {
    background-color: var(--color-accent-alpha);
    color: var(--color-accent);
}

.user-role-contributor {
    background-color: var(--color-success-alpha, rgba(34, 197, 94, 0.15));
    color: var(--color-success);
}

.user-role-viewer {
    background-color: var(--color-bg-tertiary);
    color: var(--color-text-secondary);
}

.user-menu-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: var(--spacing-xs);
    background-color: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    min-width: 160px;
    display: none;
    z-index: 200;
}

.user-menu:hover .user-menu-dropdown,
.user-menu-dropdown:hover {
    display: block;
}

.user-menu-dropdown a {
    display: block;
    padding: var(--spacing-sm) var(--spacing-md);
    color: var(--color-text-primary);
    font-size: 0.875rem;
}

.user-menu-dropdown a:hover {
    background-color: var(--color-bg-secondary);
    text-decoration: none;
}

.user-menu-dropdown .toggle-switch {
    border-top: 1px solid var(--color-border);
    border-bottom: 1px solid var(--color-border);
    margin: var(--spacing-xs) 0;
}

.user-menu-dropdown .toggle-switch:hover {
    background-color: var(--color-bg-secondary);
}

/* Messages */
.messages-container {
    position: fixed;
    top: 80px;
    right: var(--spacing-md);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    max-width: 400px;
}

.message {
    padding: var(--spacing-md);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-md);
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.message-success {
    background-color: var(--color-success-bg);
    border: 1px solid var(--color-success);
    color: var(--color-success-text);
}

.message-error {
    background-color: var(--color-danger-bg);
    border: 1px solid var(--color-danger);
    color: var(--color-danger-text);
}

.message-warning {
    background-color: var(--color-warning-bg);
    border: 1px solid var(--color-warning);
    color: var(--color-warning-text);
}

.message-info {
    background-color: var(--color-info-bg);
    border: 1px solid var(--color-info);
    color: var(--color-info-text);
}

.message-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    opacity: 0.5;
    color: inherit;
}

.message-close:hover {
    opacity: 1;
}

/* Grid Layout */
.grid {
    display: grid;
    gap: 1.5rem;
}

.grid-2 { grid-template-columns: repeat(auto-fill, minmax(400px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }

@media (max-width: 768px) {
    .grid-2, .grid-3, .grid-4 {
        grid-template-columns: 1fr;
    }
}

/* Flexbox utilities */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-sm { gap: var(--spacing-sm); }
.gap-md { gap: var(--spacing-md); }
.gap-lg { gap: var(--spacing-lg); }

/* Spacing utilities */
.mt-sm { margin-top: var(--spacing-sm); }
.mt-md { margin-top: var(--spacing-md); }
.mt-lg { margin-top: var(--spacing-lg); }
.mb-sm { margin-bottom: var(--spacing-sm); }
.mb-md { margin-bottom: var(--spacing-md); }
.mb-lg { margin-bottom: var(--spacing-lg); }

/* Text utilities */
.text-center { text-align: center; }
.text-muted { color: var(--color-text-secondary); }
.text-danger { color: var(--color-danger); }
.text-sm { font-size: 0.875rem; }
.text-lg { font-size: 1.125rem; }
.font-medium { font-weight: 500; }
.font-bold { font-weight: 600; }

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

/* Two-column layout with sidebar */
.layout-with-sidebar {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: var(--spacing-lg);
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 var(--spacing-md);
}

@media (max-width: 900px) {
    .layout-with-sidebar {
        grid-template-columns: 1fr;
    }
}

/* Sidebar */
.sidebar {
    background-color: var(--color-bg-secondary);
    border-radius: var(--radius-md);
    padding: var(--spacing-md);
    height: fit-content;
    position: sticky;
    top: 80px;
}

.sidebar-section {
    margin-bottom: var(--spacing-lg);
}

.sidebar-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-secondary);
    margin-bottom: var(--spacing-sm);
}

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

.sidebar-nav-item {
    margin-bottom: var(--spacing-xs);
}

.sidebar-nav-link {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm);
    border-radius: var(--radius-sm);
    color: var(--color-text-primary);
    font-size: 0.875rem;
}

.sidebar-nav-link:hover {
    background-color: var(--color-bg-primary);
    text-decoration: none;
}

.sidebar-nav-link.active {
    background-color: var(--color-accent);
    color: white;
}
