/* ============================================================
   THE WORLD OF SERENE — CODEX STYLESHEET
   Dark theme with gold/amber accents
   ============================================================ */

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

.hidden { display: none !important; }

/* --- CSS Variables --- */
:root {
    --bg-darkest: #0a0a0f;
    --bg-dark: #12121a;
    --bg-card: #1a1a2e;
    --bg-card-hover: #22223a;
    --bg-surface: #1e1e30;
    --bg-input: #16162a;
    --bg-sidebar: #0e0e18;

    --gold: #c9a84c;
    --gold-light: #e8cc6e;
    --gold-dim: #8a7233;
    --gold-glow: rgba(201, 168, 76, 0.3);
    --gold-subtle: rgba(201, 168, 76, 0.08);

    --text-primary: #e8e6e0;
    --text-secondary: #9a9a9a;
    --text-dim: #666;
    --text-gold: #c9a84c;

    --border: #2a2a3e;
    --border-gold: rgba(201, 168, 76, 0.3);
    --border-subtle: #1e1e30;

    --danger: #c94c4c;
    --danger-hover: #e05555;
    --success: #4cc96e;
    --info: #4c8ac9;
    --orphan-link: #7a6a6a;

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

    --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.6);
    --shadow-gold: 0 0 20px rgba(201, 168, 76, 0.15);

    --transition: 0.25s ease;
    --transition-fast: 0.15s ease;

    --font-display: 'Cinzel', serif;
    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

    --sidebar-width: 260px;
}

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

html {
    font-size: 15px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-body);
    background: var(--bg-darkest);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

a {
    color: var(--gold);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:visited {
    color: var(--gold);
}

a:hover {
    color: var(--gold-light);
}

::selection {
    background: var(--gold);
    color: var(--bg-darkest);
}

::-webkit-scrollbar {
    width: 8px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--gold-dim);
}

/* --- Sidebar --- */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    z-index: 100;
    display: flex;
    flex-direction: column;
    transform: translateX(0);
    transition: transform var(--transition);
    overflow-y: auto;
}

.sidebar.collapsed {
    transform: translateX(calc(-1 * var(--sidebar-width)));
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 16px 12px;
    border-bottom: 1px solid var(--border);
}

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

.logo-icon {
    color: var(--gold);
    filter: drop-shadow(0 0 6px var(--gold-glow));
}

.logo-text {
    font-family: var(--font-display);
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--gold);
    letter-spacing: 1px;
}

.sidebar-close {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

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

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    transition: all var(--transition-fast);
    border-left: 3px solid transparent;
}

.sidebar-link:hover,
.sidebar-link.active {
    color: var(--gold);
    background: var(--gold-subtle);
    border-left-color: var(--gold);
}

.sidebar-dashboard {
    margin-top: 8px;
}

.sidebar-categories {
    flex: 1;
    padding: 8px 0;
    overflow-y: auto;
}

.sidebar-category {
    user-select: none;
}

.sidebar-category-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    cursor: pointer;
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: all var(--transition-fast);
    border-left: 3px solid transparent;
}

.sidebar-category-header:hover {
    color: var(--gold);
    background: var(--gold-subtle);
    border-left-color: var(--gold);
}

.sidebar-category-header.active {
    color: var(--gold);
    border-left-color: var(--gold);
}

.sidebar-category-icon {
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-category-icon svg {
    width: 18px;
    height: 18px;
    color: var(--gold-dim);
}

.sidebar-category-chevron {
    transition: transform var(--transition-fast);
    color: var(--text-dim);
    font-size: 0.7rem;
}

.sidebar-category-header.expanded .sidebar-category-chevron {
    transform: rotate(180deg);
}

.sidebar-subtypes {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    background: rgba(0, 0, 0, 0.15);
}

.sidebar-subtypes.expanded {
    max-height: 500px;
}

.sidebar-subtype {
    display: block;
    padding: 6px 16px 6px 48px;
    color: var(--text-secondary);
    font-size: 0.82rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    border-left: 3px solid transparent;
}

.sidebar-subtype:hover,
.sidebar-subtype.active {
    color: var(--gold);
    background: var(--gold-subtle);
    border-left-color: var(--gold-dim);
}

.sidebar-search {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
}

.sidebar-search-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-dim);
    margin-bottom: 8px;
}

.search-input-wrapper {
    position: relative;
}

.search-input-wrapper input {
    width: 100%;
    padding: 8px 12px 8px 32px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-family: var(--font-body);
    outline: none;
    transition: border-color var(--transition-fast);
}

.search-input-wrapper input:focus {
    border-color: var(--gold-dim);
}

.search-icon-small {
    position: absolute;
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-dim);
}

/* --- Main Content --- */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    transition: margin-left var(--transition);
    padding-bottom: 60px;
}

.sidebar.collapsed ~ .main-content {
    margin-left: 0;
}

/* --- Top Bar --- */
.top-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 24px;
    background: var(--bg-dark);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}

.sidebar-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
}

.sidebar-toggle:hover {
    color: var(--gold);
    background: var(--gold-subtle);
}

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.breadcrumb a {
    color: var(--text-secondary);
}

.breadcrumb a:hover {
    color: var(--gold);
}

.breadcrumb .separator {
    color: var(--text-dim);
    font-size: 0.75rem;
}

.breadcrumb .current {
    color: var(--gold);
}

.top-bar-spacer {
    flex: 1;
}

/* --- Views --- */
.view {
    display: none;
    animation: fadeIn 0.3s ease;
}

.view.active {
    display: block;
}

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

/* --- Dashboard --- */
.dashboard {
    max-width: 1100px;
    margin: 0 auto;
    padding: 40px 24px;
}

.dashboard-header {
    text-align: center;
    margin-bottom: 48px;
}

.dashboard-search {
    position: relative;
    max-width: 500px;
    margin: 0 auto 32px;
}

.dashboard-search .search-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-dim);
}

#global-search {
    width: 100%;
    padding: 12px 20px 12px 44px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 24px;
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: var(--font-body);
    outline: none;
    transition: all var(--transition);
}

#global-search:focus {
    border-color: var(--gold-dim);
    box-shadow: var(--shadow-gold);
}

#global-search::placeholder {
    color: var(--text-dim);
    font-size: 0.85rem;
}

.dashboard-title {
    font-family: var(--font-display);
    font-size: 1.4rem;
    font-weight: 400;
    color: var(--text-secondary);
    letter-spacing: 2px;
    line-height: 1.3;
}

.title-serene {
    font-size: 4rem;
    font-weight: 700;
    color: var(--gold);
    display: block;
    letter-spacing: 8px;
    text-shadow: 0 0 40px rgba(201, 168, 76, 0.2);
}

.dashboard-subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-top: 12px;
    font-style: italic;
}

/* --- Category Grid --- */
.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 48px;
}

.category-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px 20px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    position: relative;
    overflow: hidden;
}

.category-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, transparent, var(--gold), transparent);
    opacity: 0;
    transition: opacity var(--transition);
}

.category-card:hover {
    transform: translateY(-4px);
    border-color: var(--border-gold);
    box-shadow: var(--shadow-gold);
    background: var(--bg-card-hover);
}

.category-card:hover::before {
    opacity: 1;
}

.category-card-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 16px;
    color: var(--gold);
    filter: drop-shadow(0 0 8px var(--gold-glow));
    transition: transform var(--transition);
}

.category-card:hover .category-card-icon {
    transform: scale(1.1);
}

.category-card-title {
    font-family: var(--font-display);
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
    letter-spacing: 0.5px;
}

.category-card-desc {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.category-card-count {
    margin-top: 12px;
    font-size: 0.75rem;
    color: var(--text-dim);
}

/* --- Dashboard Footer --- */
.dashboard-footer {
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
}

.footer-ornament {
    width: 80px;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--gold-dim), transparent);
}

.footer-tagline {
    color: var(--text-dim);
    font-size: 0.9rem;
    font-family: var(--font-display);
}

/* --- Category View --- */
.category-view {
    max-width: 1000px;
    margin: 0 auto;
    padding: 32px 24px;
}

.category-header {
    margin-bottom: 32px;
}

.category-title {
    font-family: var(--font-display);
    font-size: 2rem;
    color: var(--gold);
    letter-spacing: 2px;
    margin-bottom: 8px;
}

.category-description {
    color: var(--text-secondary);
    margin-bottom: 20px;
}

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

/* --- Entries List --- */
.entries-list {
    display: grid;
    gap: 12px;
}

.entry-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
}

.entry-card:hover {
    border-color: var(--border-gold);
    background: var(--bg-card-hover);
    box-shadow: var(--shadow-gold);
    transform: translateX(4px);
}

.entry-card-thumbnail {
    width: 56px;
    height: 56px;
    border-radius: var(--radius);
    object-fit: cover;
    border: 1px solid var(--border);
    flex-shrink: 0;
}

.entry-card-placeholder {
    width: 56px;
    height: 56px;
    border-radius: var(--radius);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dim);
    flex-shrink: 0;
}

.entry-card-info {
    flex: 1;
    min-width: 0;
}

.entry-card-title {
    font-family: var(--font-display);
    font-size: 1rem;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.entry-card-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.entry-card-desc {
    font-size: 0.82rem;
    color: var(--text-dim);
    margin-top: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.entries-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-dim);
}

.entries-empty-icon {
    font-size: 3rem;
    margin-bottom: 12px;
    opacity: 0.3;
}

/* --- Entry View --- */
.entry-view {
    max-width: 1200px;
    margin: 0 auto;
}

.entry-hero {
    width: 100%;
    height: 280px;
    background: var(--bg-card);
    background-size: cover;
    background-position: center;
    position: relative;
}

.entry-hero.has-image::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 100px;
    background: linear-gradient(transparent, var(--bg-darkest));
}

.entry-hero:not(.has-image) {
    height: 40px;
    background: linear-gradient(135deg, var(--bg-card), var(--bg-surface));
}

/* Change Cover button — visible on hero hover */
.hero-change-btn {
    display: none;
    position: absolute;
    bottom: 12px;
    right: 12px;
    z-index: 10;
    background: rgba(0, 0, 0, 0.65);
    color: var(--gold);
    border: 1px solid var(--gold);
    padding: 5px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
}

.entry-hero.has-image:hover .hero-change-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.hero-change-btn:hover {
    background: var(--gold);
    color: var(--bg-darkest);
}

.entry-layout {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 32px;
    padding: 24px 32px;
}

.entry-main {
    min-width: 0;
}

.entry-title {
    font-family: var(--font-display);
    font-size: 2.2rem;
    color: var(--text-primary);
    letter-spacing: 1px;
    margin-bottom: 12px;
}

.entry-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.meta-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.meta-tag svg {
    width: 14px;
    height: 14px;
    color: var(--gold-dim);
}

.entry-actions-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

/* --- Entry Fields --- */
.entry-fields {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.field-item {
    padding: 12px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.field-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--gold-dim);
    margin-bottom: 4px;
}

.field-value {
    font-size: 0.95rem;
    color: var(--text-primary);
}

/* --- Entry Description --- */
.entry-description {
    margin-bottom: 32px;
    line-height: 1.8;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.entry-description p {
    margin-bottom: 12px;
}

/* Wiki-links in description */
.wiki-link {
    color: var(--gold);
    cursor: pointer;
    border-bottom: 1px dotted var(--gold-dim);
    transition: all var(--transition-fast);
    position: relative;
}

.wiki-link:hover {
    color: var(--gold-light);
    text-shadow: 0 0 8px var(--gold-glow);
}

.wiki-link.orphan {
    color: var(--orphan-link);
    border-bottom-color: var(--orphan-link);
}

/* --- Entry Sections --- */
.entry-section {
    margin-bottom: 28px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.section-title {
    font-family: var(--font-display);
    font-size: 1rem;
    color: var(--gold);
    letter-spacing: 1px;
    margin-bottom: 16px;
}

/* --- Gallery --- */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 12px;
}

.gallery-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    border: 1px solid var(--border);
    transition: all var(--transition);
}

.gallery-item:hover {
    border-color: var(--gold-dim);
    box-shadow: var(--shadow-gold);
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.gallery-item-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    opacity: 0;
    transition: opacity var(--transition);
}

.gallery-item:hover .gallery-item-overlay {
    opacity: 1;
}

.gallery-item-caption {
    font-size: 0.75rem;
    color: var(--text-primary);
}

.gallery-item-actions {
    display: flex;
    gap: 6px;
    align-items: center;
    align-self: flex-end;
}

.gallery-item-delete {
    background: var(--danger);
    border: none;
    color: white;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.gallery-item-set-cover {
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid var(--gold);
    color: var(--gold);
    padding: 2px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.7rem;
    font-weight: 600;
    white-space: nowrap;
}

.gallery-item-set-cover:hover {
    background: var(--gold);
    color: var(--bg-darkest);
}

.gallery-upload {
    margin-top: 8px;
}

/* --- Keywords --- */
.keywords-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.keyword-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 14px;
    background: var(--gold-subtle);
    border: 1px solid var(--border-gold);
    border-radius: 20px;
    font-size: 0.82rem;
    color: var(--gold);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.keyword-pill:hover {
    background: var(--gold-glow);
    color: var(--gold-light);
}

.keyword-pill .keyword-remove {
    color: var(--text-dim);
    cursor: pointer;
    font-size: 0.9rem;
    line-height: 1;
}

.keyword-pill .keyword-remove:hover {
    color: var(--danger);
}

.keyword-add {
    display: flex;
    gap: 8px;
}

#keyword-input {
    flex: 1;
    max-width: 250px;
}

/* --- Backlinks --- */
.backlinks-list {
    display: grid;
    gap: 8px;
}

.backlink-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all var(--transition-fast);
}

.backlink-item:hover {
    border-color: var(--border-gold);
    background: var(--bg-card-hover);
}

.backlink-category {
    font-size: 0.7rem;
    color: var(--text-dim);
    text-transform: uppercase;
}

/* --- Relationships Panel --- */
.entry-sidebar {
    position: sticky;
    top: 80px;
    align-self: start;
}

.relationships-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
}

.panel-title {
    font-family: var(--font-display);
    font-size: 0.95rem;
    color: var(--gold);
    letter-spacing: 1px;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.relationships-list {
    display: grid;
    gap: 10px;
    margin-bottom: 12px;
}

.relationship-group-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-dim);
    margin-top: 8px;
    margin-bottom: 4px;
}

.relationship-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.relationship-card:hover {
    border-color: var(--border-gold);
    background: var(--bg-card-hover);
}

.rel-card-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bg-card);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--gold-dim);
    flex-shrink: 0;
}

.rel-card-info {
    flex: 1;
    min-width: 0;
}

.rel-card-title {
    font-size: 0.85rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rel-card-type {
    font-size: 0.7rem;
    color: var(--text-dim);
}

.rel-card-delete {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 2px 4px;
    font-size: 0.8rem;
    opacity: 0;
    transition: all var(--transition-fast);
}

.relationship-card:hover .rel-card-delete {
    opacity: 1;
}

.rel-card-delete:hover {
    color: var(--danger);
}

/* --- Forms --- */
.entry-form-view {
    max-width: 800px;
    margin: 0 auto;
    padding: 32px 24px;
}

.form-title {
    font-family: var(--font-display);
    font-size: 1.8rem;
    color: var(--gold);
    margin-bottom: 28px;
    letter-spacing: 1px;
}

.entry-form {
    display: grid;
    gap: 20px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    font-weight: 500;
}

.input-styled,
.select-styled,
.textarea-styled {
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: var(--font-body);
    outline: none;
    transition: border-color var(--transition-fast);
}

.input-styled:focus,
.select-styled:focus,
.textarea-styled:focus {
    border-color: var(--gold-dim);
}

.select-styled {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M6 8L1 3h10z' fill='%239a9a9a'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

.textarea-styled {
    resize: vertical;
    min-height: 120px;
    line-height: 1.7;
}

.form-template-fields {
    display: grid;
    gap: 16px;
}

.template-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.template-field-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.template-field-header label {
    flex: 1;
}

.field-remove-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 0 4px;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    opacity: 0;
}

.template-field:hover .field-remove-btn {
    opacity: 1;
}

.field-remove-btn:hover {
    color: var(--error);
    background: rgba(220, 53, 69, 0.15);
}

.template-field .field-prompt {
    font-size: 0.78rem;
    color: var(--text-dim);
    font-style: italic;
}

.entry-add-field-row {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border-subtle);
}

.entry-add-field-row .input-styled {
    flex: 1;
}

.form-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-family: var(--font-body);
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.btn:hover {
    background: var(--bg-card-hover);
    border-color: var(--text-dim);
}

.btn-gold {
    background: linear-gradient(135deg, var(--gold), var(--gold-dim));
    border-color: var(--gold);
    color: var(--bg-darkest);
    font-weight: 600;
}

.btn-gold:hover {
    background: linear-gradient(135deg, var(--gold-light), var(--gold));
    border-color: var(--gold-light);
    box-shadow: var(--shadow-gold);
}

.btn-danger {
    background: var(--danger);
    border-color: var(--danger);
    color: white;
}

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

.btn-outline {
    background: transparent;
    border-color: var(--border);
    color: var(--text-secondary);
}

.btn-outline:hover {
    border-color: var(--gold-dim);
    color: var(--gold);
}

.btn-sm {
    padding: 6px 14px;
    font-size: 0.8rem;
}

.btn-full {
    width: 100%;
}

/* --- Search Results --- */
.search-view {
    max-width: 900px;
    margin: 0 auto;
    padding: 32px 24px;
}

.search-results-title {
    font-family: var(--font-display);
    font-size: 1.5rem;
    color: var(--gold);
    margin-bottom: 8px;
}

.search-results-info {
    color: var(--text-dim);
    margin-bottom: 24px;
    font-size: 0.85rem;
}

/* --- Graph View --- */
.graph-view {
    height: calc(100vh - 120px);
    display: flex;
    flex-direction: column;
    padding: 16px;
}

.graph-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.graph-header h2 {
    font-family: var(--font-display);
    font-size: 1.5rem;
    color: var(--gold);
}

.graph-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.graph-canvas {
    flex: 1;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    cursor: grab;
}

.graph-canvas:active {
    cursor: grabbing;
}

/* --- Settings --- */
.settings-view {
    max-width: 700px;
    margin: 0 auto;
    padding: 32px 24px;
}

.settings-view h2 {
    font-family: var(--font-display);
    font-size: 1.8rem;
    color: var(--gold);
    margin-bottom: 28px;
}

.settings-section {
    margin-bottom: 36px;
    padding-bottom: 28px;
    border-bottom: 1px solid var(--border);
}

.settings-section h3 {
    font-family: var(--font-display);
    font-size: 1.1rem;
    color: var(--text-primary);
    margin-bottom: 16px;
}

.settings-description {
    color: var(--text-dim);
    font-size: 0.85rem;
    margin-bottom: 16px;
}

.settings-actions {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

/* Template Editor */
.template-editor {
    margin-bottom: 16px;
}

.template-editor-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-subtle);
}

.template-editor-item:last-child {
    border-bottom: none;
}

.template-drag-handle {
    cursor: grab;
    color: var(--text-dim);
    font-size: 1rem;
    padding: 8px 4px 0;
    user-select: none;
}

.template-drag-handle:hover {
    color: var(--gold);
}

.template-editor-item.dragging {
    opacity: 0.4;
}

.template-editor-fields {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.template-editor-fields .field-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.template-editor-fields .field-name-input {
    width: 140px;
    flex-shrink: 0;
    font-weight: 600;
}

.template-editor-fields .field-prompt-input {
    flex: 1;
}

.template-editor-fields .field-type-select {
    width: 90px;
    flex-shrink: 0;
    font-size: 0.8rem;
}

.template-editor-fields .field-options-input {
    flex: 1;
    font-size: 0.8rem;
}

.template-remove-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 6px;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.template-remove-btn:hover {
    color: var(--error);
    background: rgba(220, 53, 69, 0.15);
}

.template-add-row {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.template-add-row .input-styled {
    flex: 1;
}

.template-save-status {
    margin-top: 8px;
    font-size: 0.85rem;
    min-height: 20px;
}

.template-save-status.success {
    color: var(--success, #5cb85c);
}

.template-save-status.error {
    color: var(--error);
}

.template-editor-empty {
    color: var(--text-muted);
    font-style: italic;
    text-align: center;
    padding: 20px;
}

.sync-status {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 0.85rem;
    margin-top: 12px;
}

.sync-status.connected {
    background: rgba(76, 201, 110, 0.1);
    border: 1px solid rgba(76, 201, 110, 0.3);
    color: var(--success);
}

.sync-status.disconnected {
    background: rgba(201, 76, 76, 0.1);
    border: 1px solid rgba(201, 76, 76, 0.3);
    color: var(--danger);
}

.sync-log {
    margin-top: 20px;
}

.sync-log-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 6px;
    font-size: 0.82rem;
}

.dictionary-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.dictionary-word {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 0.82rem;
    color: var(--text-primary);
}

.dictionary-word .word-remove {
    color: var(--text-dim);
    cursor: pointer;
    font-size: 0.8rem;
}

.dictionary-word .word-remove:hover {
    color: var(--danger);
}

/* --- Modals --- */
.modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal.hidden {
    display: none;
}

.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px;
    min-width: 400px;
    max-width: 500px;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.2s ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.modal-content h3 {
    font-family: var(--font-display);
    font-size: 1.2rem;
    color: var(--gold);
    margin-bottom: 20px;
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* Sub-type management */
.subtype-manage-list {
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 16px;
}

.subtype-manage-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 0.9rem;
    color: var(--text-primary);
}

.subtype-manage-item:last-child {
    border-bottom: none;
}

.subtype-drag-handle {
    cursor: grab;
    color: var(--text-dim);
    font-size: 1rem;
    padding: 0 4px;
    user-select: none;
    transition: color var(--transition-fast);
}

.subtype-drag-handle:hover {
    color: var(--gold);
}

.subtype-manage-item.dragging {
    opacity: 0.4;
    background: var(--gold-subtle);
}

.subtype-manage-item.drag-over {
    border-top-color: var(--gold);
}

.subtype-manage-item .subtype-name {
    flex: 1;
}

.subtype-manage-item .subtype-count {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-right: 12px;
}

.subtype-delete-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.subtype-delete-btn:hover {
    color: var(--error);
    background: rgba(220, 53, 69, 0.15);
}

.subtype-add-row {
    display: flex;
    gap: 8px;
}

.subtype-add-row .input-styled {
    flex: 1;
}

.btn-small {
    padding: 6px 10px;
    font-size: 0.85rem;
    min-width: auto;
}

.subtype-empty {
    color: var(--text-muted);
    font-style: italic;
    text-align: center;
    padding: 16px;
}

.rel-target-results {
    max-height: 200px;
    overflow-y: auto;
    margin-top: 8px;
}

.rel-target-item {
    padding: 8px 12px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    transition: background var(--transition-fast);
}

.rel-target-item:hover {
    background: var(--bg-card-hover);
}

.rel-target-item.selected {
    background: var(--gold-subtle);
    color: var(--gold);
}

.rel-target-item-category {
    font-size: 0.7rem;
    color: var(--text-dim);
    margin-left: 8px;
}

/* --- Wiki-link Tooltip --- */
.wiki-tooltip {
    position: fixed;
    z-index: 300;
    background: var(--bg-surface);
    border: 1px solid var(--border-gold);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    max-width: 320px;
    display: flex;
    overflow: hidden;
    pointer-events: none;
    animation: tooltipIn 0.15s ease;
}

.wiki-tooltip.hidden {
    display: none;
}

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

.tooltip-thumbnail {
    width: 80px;
    min-height: 80px;
    background: var(--bg-card);
    background-size: cover;
    background-position: center;
    flex-shrink: 0;
}

.tooltip-thumbnail:empty {
    display: none;
}

.tooltip-content {
    padding: 12px;
    flex: 1;
}

.tooltip-category {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--gold-dim);
    margin-bottom: 4px;
}

.tooltip-title {
    font-family: var(--font-display);
    font-size: 0.95rem;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.tooltip-description {
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

/* --- Wiki-link Autocomplete Dropdown --- */
.wiki-link-dropdown {
    position: absolute;
    background: var(--bg-surface);
    border: 1px solid var(--border-gold);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    max-height: 200px;
    overflow-y: auto;
    z-index: 150;
    min-width: 250px;
}

.wiki-link-dropdown.hidden {
    display: none;
}

.wiki-link-option {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background var(--transition-fast);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.wiki-link-option:hover,
.wiki-link-option.active {
    background: var(--gold-subtle);
    color: var(--gold);
}

.wiki-link-option-category {
    font-size: 0.7rem;
    color: var(--text-dim);
}

/* --- Lightbox --- */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 250;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
}

.lightbox.hidden {
    display: none;
}

.lightbox-close {
    position: absolute;
    top: 16px;
    right: 24px;
    background: none;
    border: none;
    color: white;
    font-size: 2rem;
    cursor: pointer;
    z-index: 1;
}

.lightbox img {
    max-width: 90vw;
    max-height: 85vh;
    object-fit: contain;
    border-radius: var(--radius);
}

.lightbox-caption {
    color: var(--text-secondary);
    margin-top: 12px;
    font-size: 0.9rem;
}

/* --- Spellcheck Popup --- */
.spellcheck-popup {
    position: fixed;
    z-index: 250;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    min-width: 180px;
    padding: 8px 0;
}

.spellcheck-popup.hidden {
    display: none;
}

.spellcheck-word {
    padding: 6px 14px;
    font-size: 0.8rem;
    color: var(--text-muted);
    font-style: italic;
    border-bottom: 1px solid var(--border-subtle);
}

.spellcheck-suggestions {
    max-height: 200px;
    overflow-y: auto;
    padding: 4px 0;
}

.spellcheck-loading,
.spellcheck-none,
.spellcheck-ok {
    padding: 8px 14px;
    font-size: 0.85rem;
    color: var(--text-muted);
    font-style: italic;
}

.spellcheck-ok {
    color: var(--success, #5cb85c);
}

.spellcheck-divider {
    border-top: 1px solid var(--border-subtle);
    margin: 2px 0;
}

.spellcheck-suggestion {
    display: block;
    width: 100%;
    padding: 6px 14px;
    cursor: pointer;
    font-size: 0.85rem;
    background: none;
    border: none;
    text-align: left;
    color: var(--text-primary);
    transition: background var(--transition-fast);
}

.spellcheck-suggestion:hover {
    background: var(--gold-subtle);
    color: var(--gold);
}

.spellcheck-actions {
    border-top: 1px solid var(--border);
    padding: 4px 0 0;
    margin-top: 4px;
}

.spellcheck-btn {
    display: block;
    width: 100%;
    padding: 6px 14px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-family: var(--font-body);
    cursor: pointer;
    text-align: left;
    transition: all var(--transition-fast);
}

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

/* Misspelled word underline */
.misspelled {
    text-decoration: underline wavy;
    text-decoration-color: var(--danger);
    cursor: pointer;
}

/* --- Bottom Nav --- */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: var(--sidebar-width);
    right: 0;
    display: flex;
    justify-content: center;
    gap: 32px;
    padding: 10px 16px;
    background: var(--bg-dark);
    border-top: 1px solid var(--border);
    z-index: 50;
    transition: left var(--transition);
}

.sidebar.collapsed ~ .main-content ~ .bottom-nav,
.sidebar.collapsed ~ .bottom-nav {
    left: 0;
}

.bottom-nav-link {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
    font-size: 0.82rem;
    padding: 6px 16px;
    border-radius: var(--radius);
    transition: all var(--transition-fast);
}

.bottom-nav-link:hover,
.bottom-nav-link.active {
    color: var(--gold);
    background: var(--gold-subtle);
}

/* --- Description Editor Wrapper --- */
.description-editor-wrapper {
    position: relative;
}

/* --- Docx Drag & Drop Overlay --- */
.docx-drop-overlay {
    position: absolute;
    inset: 0;
    background: rgba(184, 134, 11, 0.15);
    border: 2px dashed var(--gold);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    pointer-events: none;
}

.docx-drop-overlay span {
    background: var(--bg-card);
    color: var(--gold);
    padding: 0.5rem 1.2rem;
    border-radius: 6px;
    font-weight: 600;
    font-size: 1rem;
    letter-spacing: 0.5px;
}

.docx-drop-overlay.hidden {
    display: none;
}

/* --- Responsive --- */
@media (max-width: 900px) {
    .entry-layout {
        grid-template-columns: 1fr;
    }

    .entry-sidebar {
        position: static;
    }

    .form-row {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(calc(-1 * var(--sidebar-width)));
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }

    .bottom-nav {
        left: 0;
    }

    .category-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    }

    .title-serene {
        font-size: 2.8rem;
        letter-spacing: 4px;
    }

    .modal-content {
        min-width: auto;
        margin: 16px;
    }

    .auth-nav { gap: 6px; }
    .auth-display-name { display: none; }
    .auth-admin-link { display: none !important; }
    .admin-panel { padding: 16px; }
    .admin-table { font-size: 0.75rem; }
    .admin-actions-cell { flex-direction: column; gap: 4px; }
}

/* ============================================================
   AUTH — hidden state rules
   ============================================================ */
.auth-guest.hidden,
.auth-user.hidden,
.auth-dropdown.hidden,
.auth-error.hidden,
#login-modal.hidden,
#register-modal.hidden,
.profile-field-edit.hidden,
.profile-bio-edit.hidden,
.profile-connection-edit.hidden {
    display: none !important;
}

/* ============================================================
   AUTH NAV — top right
   ============================================================ */

.auth-nav {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.auth-guest {
    display: flex;
    align-items: center;
    gap: 8px;
}

.auth-user {
    display: flex;
    align-items: center;
    gap: 10px;
    position: relative;
}

.auth-admin-link {
    font-size: 0.8rem;
    color: var(--gold);
    cursor: pointer;
    padding: 4px 10px;
    border: 1px solid var(--gold-dark);
    border-radius: 5px;
    transition: background var(--transition);
    white-space: nowrap;
}

.auth-admin-link:hover {
    background: rgba(184,134,11,0.15);
}

.auth-avatar-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background var(--transition);
    position: relative;
}

.auth-avatar-btn:hover {
    background: var(--bg-card);
}

.auth-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--gold-dark);
    color: var(--bg-darkest);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    background-size: cover;
    background-position: center;
    flex-shrink: 0;
}

.auth-display-name {
    font-size: 0.85rem;
    color: var(--text-primary);
    font-weight: 500;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Dropdown */
.auth-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    min-width: 160px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    z-index: 200;
    overflow: hidden;
}

.auth-dropdown-item {
    width: 100%;
    background: none;
    border: none;
    padding: 10px 16px;
    text-align: left;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.875rem;
    transition: background var(--transition);
}

.auth-dropdown-item:hover {
    background: var(--bg-surface);
    color: var(--gold);
}

.auth-dropdown-divider {
    height: 1px;
    background: var(--border-color);
    margin: 4px 0;
}

.auth-dropdown-logout {
    color: var(--danger);
}

.auth-dropdown-logout:hover {
    background: rgba(220,38,38,0.1);
    color: var(--danger);
}

/* ============================================================
   AUTH MODALS — login & register
   ============================================================ */

.auth-modal-content {
    max-width: 400px;
}

.auth-modal-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: var(--gold);
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.auth-modal-title {
    text-align: center;
    font-family: var(--font-display);
    font-size: 1.4rem;
    color: var(--gold);
    margin-bottom: 20px;
    font-weight: 600;
}

.auth-error {
    background: rgba(220,38,38,0.15);
    border: 1px solid var(--danger);
    color: #fca5a5;
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 0.875rem;
    margin-bottom: 14px;
}

.auth-remember-row {
    margin-bottom: 12px;
}

.auth-remember-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.auth-switch {
    text-align: center;
    margin-top: 14px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.auth-switch a {
    color: var(--gold);
    text-decoration: none;
}

.auth-switch a:hover {
    text-decoration: underline;
}

.auth-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 400;
}

/* Gated buttons */
.gated {
    opacity: 0.45;
    cursor: not-allowed !important;
    pointer-events: auto !important;
    filter: grayscale(0.4);
}

.gated-nav {
    opacity: 0.4;
    pointer-events: none;
}

/* ============================================================
   ADMIN PANEL
   ============================================================ */

.admin-panel {
    padding: 24px 32px;
    max-width: 1100px;
    margin: 0 auto;
}

.admin-panel-title {
    font-family: var(--font-display);
    color: var(--gold);
    font-size: 1.6rem;
    margin-bottom: 20px;
}

.admin-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 24px;
}

.admin-tab {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 10px 20px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all var(--transition);
    margin-bottom: -1px;
}

.admin-tab:hover { color: var(--gold); }

.admin-tab.active {
    color: var(--gold);
    border-bottom-color: var(--gold);
}

.admin-tab-content { }
.admin-tab-content.hidden { display: none; }

.admin-toolbar {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    align-items: center;
}

.admin-toolbar .input-styled {
    max-width: 260px;
}

.admin-section-desc {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 16px;
}

.admin-table-wrap {
    overflow-x: auto;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.admin-table th {
    text-align: left;
    padding: 10px 12px;
    color: var(--gold);
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
    font-family: var(--font-display);
    font-size: 0.8rem;
    letter-spacing: 0.5px;
}

.admin-table td {
    padding: 10px 12px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    vertical-align: middle;
    color: var(--text-primary);
}

.admin-table tr:hover td {
    background: var(--bg-surface);
}

.row-banned td { opacity: 0.5; }
.row-suspended td { opacity: 0.65; }

.status-badge {
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.status-badge.active { background: rgba(34,197,94,0.15); color: #86efac; }
.status-badge.suspended { background: rgba(234,179,8,0.15); color: #fde047; }
.status-badge.banned { background: rgba(220,38,38,0.15); color: #fca5a5; }

.admin-actions-cell {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.btn-xs {
    padding: 3px 8px;
    font-size: 0.72rem;
}

.admin-self-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-style: italic;
}

.select-sm {
    padding: 3px 6px;
    font-size: 0.8rem;
}

/* Permissions matrix */
.permissions-table td,
.permissions-table th { text-align: center; }
.permissions-table td:first-child,
.permissions-table th:first-child { text-align: left; }

.perm-checkbox { width: 16px; height: 16px; cursor: pointer; accent-color: var(--gold); }
.perm-locked { font-size: 0.7rem; color: var(--text-muted); }
.perm-always { color: #86efac; font-size: 0.85rem; }

/* Audit log */
.audit-time { color: var(--text-muted); font-size: 0.78rem; white-space: nowrap; }
.audit-ip { color: var(--text-muted); font-size: 0.78rem; font-family: monospace; }
.audit-action {
    font-size: 0.72rem;
    padding: 2px 7px;
    border-radius: 8px;
    font-weight: 600;
    text-transform: uppercase;
    background: var(--bg-surface);
    color: var(--text-secondary);
}
.audit-login { background: rgba(34,197,94,0.1); color: #86efac; }
.audit-login_failed { background: rgba(220,38,38,0.1); color: #fca5a5; }
.audit-register { background: rgba(59,130,246,0.1); color: #93c5fd; }
.audit-delete { background: rgba(220,38,38,0.15); color: #fca5a5; }
.audit-ban { background: rgba(220,38,38,0.15); color: #fca5a5; }
.audit-role_change { background: rgba(234,179,8,0.1); color: #fde047; }

/* Pending edits */
.admin-pending-item {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 14px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 10px;
}

.admin-pending-meta { font-size: 0.875rem; color: var(--text-primary); }
.admin-pending-time { color: var(--text-muted); font-size: 0.78rem; margin-left: 10px; }
.admin-pending-actions { display: flex; gap: 8px; flex-shrink: 0; }

.admin-loading { color: var(--text-muted); padding: 20px; text-align: center; }
.admin-empty  { color: var(--text-muted); padding: 20px; text-align: center; font-style: italic; }

/* ============================================================
   NOTIFICATIONS
   ============================================================ */

.notif-bell-wrap {
    position: relative;
}

.notif-bell {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px 6px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    position: relative;
    transition: color var(--transition), background var(--transition);
}

.notif-bell:hover { color: var(--gold); background: rgba(184,134,11,0.1); }

.notif-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    background: #e53e3e;
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 3px;
    pointer-events: none;
}

.notif-badge.hidden { display: none !important; }

.notif-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 320px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.4);
    z-index: 900;
    overflow: hidden;
}

.notif-dropdown.hidden { display: none !important; }

.notif-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.notif-mark-read {
    background: none;
    border: none;
    color: var(--gold);
    cursor: pointer;
    font-size: 0.75rem;
    padding: 0;
}
.notif-mark-read:hover { text-decoration: underline; }

.notif-list { max-height: 320px; overflow-y: auto; }

.notif-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    transition: background var(--transition);
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--surface-hover, rgba(255,255,255,0.04)); }
.notif-item.unread { border-left: 3px solid var(--gold); padding-left: 13px; }

.notif-message { font-size: 0.85rem; color: var(--text-primary); line-height: 1.4; }
.notif-time    { font-size: 0.75rem; color: var(--text-muted); margin-top: 3px; }
.notif-empty   { padding: 20px; text-align: center; color: var(--text-muted); font-style: italic; font-size: 0.85rem; }

/* ============================================================
   PROFILE PAGE
   ============================================================ */

.profile-page {
    max-width: 900px;
    margin: 0 auto;
    padding: 24px 24px 60px;
}

/* Banner zone: just the banner, no avatar overlap */
.profile-banner-zone {
    position: relative;
    margin-bottom: 0;
}

.profile-banner {
    width: 100%;
    height: 180px;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    background-size: cover;
    background-position: center;
    border-radius: 10px;
    position: relative;
    overflow: hidden;
}

.profile-banner-btn {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0,0,0,0.5);
    color: rgba(255,255,255,0.7);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 5px;
    padding: 3px 8px;
    font-size: 0.7rem;
    cursor: pointer;
    transition: all var(--transition);
    letter-spacing: 0.02em;
}
.profile-banner-btn:hover { background: rgba(0,0,0,0.75); color: #fff; }
.profile-banner-btn.hidden { display: none !important; }

/* Avatar is part of the header row, sits cleanly below the banner */
.profile-avatar-wrap {
    position: relative;
    flex-shrink: 0;
}

.profile-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--gold);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    font-weight: 700;
    color: #fff;
    border: 3px solid var(--surface);
    background-size: cover;
    background-position: center;
}

.profile-avatar-btn {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--surface);
    border: 2px solid var(--border);
    color: var(--text-muted);
    font-size: 0.65rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}
.profile-avatar-btn:hover { background: var(--gold); color: #fff; border-color: var(--gold); }
.profile-avatar-btn.hidden { display: none !important; }

/* Header row: avatar + name + actions all in one clean row below banner */
.profile-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 32px 8px 20px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.profile-identity {
    flex: 1;
    min-width: 0;
}

.profile-display-name {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--profile-accent, var(--gold));
    margin: 0 0 2px 0;
    line-height: 1.2;
}

.profile-custom-title {
    font-size: 0.82rem;
    color: var(--text-muted);
    font-style: italic;
    margin-bottom: 3px;
}

.profile-meta {
    display: flex;
    gap: 8px;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.profile-actions {
    flex-shrink: 0;
}

.profile-admin-bar {
    background: rgba(184,134,11,0.08);
    border: 1px solid rgba(184,134,11,0.25);
    border-radius: 8px;
    padding: 10px 16px;
    font-size: 0.82rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin: 0 0 20px 0;
}
.profile-admin-bar.hidden { display: none !important; }

.admin-bar-badge {
    background: var(--gold);
    color: #000;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.admin-bar-panel-link {
    margin-left: auto;
}

.profile-content {
    padding: 0 8px;
    display: flex;
    flex-direction: column;
    gap: 28px;
}

.profile-section {
    border-bottom: 1px solid var(--border);
    padding-bottom: 24px;
}
.profile-section:last-child { border-bottom: none; }

.profile-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.profile-section-header h3 {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin: 0;
}

.profile-field-text {
    font-size: 0.92rem;
    color: var(--text-primary);
    line-height: 1.6;
    white-space: pre-wrap;
}

.profile-empty-hint {
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.85rem;
}

.profile-field-edit.hidden { display: none !important; }
.profile-bio-edit.hidden   { display: none !important; }
.profile-connection-edit.hidden { display: none !important; }

.profile-textarea {
    width: 100%;
    resize: vertical;
    min-height: 80px;
    box-sizing: border-box;
}

.profile-edit-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.profile-entries-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}

.profile-entry-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px;
    cursor: pointer;
    transition: border-color var(--transition), background var(--transition);
}
.profile-entry-card:hover {
    border-color: var(--gold-dark);
    background: rgba(184,134,11,0.06);
}

.profile-entry-title {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.profile-entry-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Profile settings modal */
.profile-settings-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.profile-settings-modal.hidden { display: none !important; }

.form-group-inline {
    display: flex;
    align-items: center;
    gap: 8px;
}
.form-group-inline label { margin: 0; cursor: pointer; }
.form-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 400;
    margin-left: 6px;
}
.admin-error  { color: var(--danger);     padding: 20px; text-align: center; }
