    :root {
        --bg: #fafafa;
        --bg-card: #ffffff;
        --text: #1a1a1a;
        --text-muted: #666666;
        --border: #e0e0e0;
        --primary: #2563eb;
        --primary-hover: #1d4ed8;
        --danger: #dc2626;
        --danger-hover: #b91c1c;
        --success: #16a34a;
        --tag-bg: #e0e7ff;
        --tag-text: #3730a3;

    }

    @media (prefers-color-scheme: dark) {
        :root {
            --bg: #0f0f0f;
            --bg-card: #1a1a1a;
            --text: #f0f0f0;
            --text-muted: #999999;
            --border: #333333;
            --primary: #3b82f6;
            --primary-hover: #60a5fa;
            --danger: #ef4444;
            --danger-hover: #f87171;
            --tag-bg: #312e81;
            --tag-text: #c7d2fe;

        }
    }

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

    body {
        font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
        background: var(--bg);
        color: var(--text);
        line-height: 1.6;
        min-height: 100vh;
    }

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

    a:hover {
        text-decoration: underline;
    }

    .container {
        max-width: 1200px;
        margin: 0 auto;
        padding: 0 0.9rem;
    }

    /* Header */
    header {
        background: var(--bg-card);
        border-bottom: 1px solid var(--border);
        padding: 0.6rem 0;
        position: sticky;
        top: 0;
        z-index: 100;
    }

    header .container {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 1rem;
    }

    .logo {
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
        font-size: 1.1rem;
        font-weight: 700;
        color: var(--text);
    }

    .logo-mark {
        width: 28px;
        height: 28px;
        flex-shrink: 0;
    }

    .logo:hover {
        text-decoration: none;
    }

    .logo-cluster {
        display: inline-flex;
        align-items: center;
        gap: 0.55rem;
        min-width: 0;
    }

    .deploy-hint {
        color: var(--text-muted);
        font-size: 0.72rem;
        line-height: 1;
        border: 1px solid var(--border);
        border-radius: 9999px;
        padding: 0.22rem 0.5rem;
        white-space: nowrap;
        background: var(--bg);
    }

    nav {
        display: flex;
        align-items: center;
        gap: 1.25rem;
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    nav a {
        display: inline-flex;
        align-items: center;
        gap: 0.35em;
        color: var(--text-muted);
        font-weight: 500;
        font-size: 0.92rem;
        white-space: nowrap;
    }

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

    nav a[aria-current="page"] {
        color: var(--text);
        font-weight: 600;
    }

    /* Nav dropdown */
    .nav-dropdown {
        position: relative;
    }

    .nav-dropdown-toggle {
        background: none;
        border: none;
        color: var(--text-muted);
        font-weight: 500;
        font-size: 0.92rem;
        cursor: pointer;
        padding: 0;
        font-family: inherit;
    }

    .nav-dropdown-toggle:hover,
    .nav-dropdown-toggle.has-active {
        color: var(--text);
    }

    .nav-dropdown-menu {
        display: none;
        position: absolute;
        right: 0;
        top: calc(100% + 0.4rem);
        background: var(--bg-card);
        border: 1px solid var(--border);
        border-radius: 8px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        min-width: 150px;
        z-index: 200;
        padding: 0.35rem 0;
        flex-direction: column;
    }

    .nav-dropdown.open .nav-dropdown-menu {
        display: flex;
    }

    .nav-dropdown-menu a {
        display: flex;
        align-items: center;
        gap: 0.4em;
        padding: 0.45rem 1rem;
        color: var(--text-muted);
        font-weight: 500;
        font-size: 0.92rem;
        white-space: nowrap;
    }

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

    .nav-dropdown-menu a[aria-current="page"] {
        color: var(--text);
        font-weight: 600;
    }

    .nav-dropdown-divider {
        border: none;
        border-top: 1px solid var(--border);
        margin: 0.25rem 0;
    }

    .nav-dropdown--user {
        margin-left: auto;
    }

    .nav-dropdown--user .nav-dropdown-toggle {
        display: flex;
        align-items: center;
    }

    .avatar {
        width: 28px;
        height: 28px;
        border-radius: 50%;
    }

    /* Buttons */
    .btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
        padding: 0.5rem 1rem;
        border: 1px solid transparent;
        border-radius: 6px;
        font-size: 0.875rem;
        font-weight: 500;
        cursor: pointer;
        transition: background 0.15s, transform 0.1s;
    }

    .btn:hover {
        text-decoration: none;
    }

    .btn:active {
        transform: scale(0.98);
    }

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

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

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

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

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

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

    .btn-small {
        padding: 0.25rem 0.5rem;
        font-size: 0.75rem;
    }

    /* Forms */
    .form-group {
        margin-bottom: 1rem;
    }

    label {
        display: block;
        margin-bottom: 0.25rem;
        font-weight: 500;
        font-size: 0.875rem;
    }

    input[type="text"],
    input[type="url"],
    input[type="search"],
    textarea,
    select {
        width: 100%;
        padding: 0.625rem 0.75rem;
        border: 1px solid var(--border);
        border-radius: 6px;
        font-size: 1rem;
        background: var(--bg-card);
        color: var(--text);
    }

    input:focus,
    textarea:focus,
    select:focus {
        outline: none;
        border-color: var(--primary);
        box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
    }

    textarea {
        resize: vertical;
        min-height: 100px;
    }

    select[multiple] {
        min-height: 120px;
    }

    .help-text {
        font-size: 0.75rem;
        color: var(--text-muted);
        margin-top: 0.25rem;
    }

    .notes-preview {
        margin-top: 0.6rem;
        padding: 0.75rem;
        border: 1px solid var(--border);
        border-radius: 8px;
        background: var(--bg);
    }

    /* Cards */
    .card {
        background: var(--bg-card);
        border: 1px solid var(--border);
        border-radius: 8px;
        padding: 1rem;
        margin-bottom: 1rem;
    }

    /* Main layout */
    main {
        padding: 0.7rem 0 1.25rem;
    }

    .page-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 0.85rem;
        flex-wrap: wrap;
        gap: 0.75rem;
    }

    .page-title {
        font-size: 1.3rem;
        font-weight: 600;
        line-height: 1.25;
    }

    /* Search */
    .search-bar {
        display: flex;
        margin-bottom: 1rem;
    }

    .chat-search {
        flex-direction: column;
        gap: 0.5rem;
    }

    .chat-label {
        font-size: 0.75rem;
        font-weight: 600;
        letter-spacing: 0.05em;
        text-transform: uppercase;
        color: var(--text-muted);
    }

    .chat-input-row {
        display: flex;
        gap: 0.5rem;
    }

    .chat-mode-row {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        flex-wrap: wrap;
    }

    .chat-mode-label {
        font-size: 0.75rem;
        color: var(--text-muted);
    }

    .chat-mode-row select {
        width: auto;
        min-width: 120px;
        font-size: 0.875rem;
        padding: 0.4rem 0.6rem;
    }

    .chat-input-row input {
        flex: 1;
    }

    .home-controls {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        margin-bottom: 0.75rem;
    }

    .home-search-toolbar {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        min-width: 0;
        flex: 1;
    }

    .home-search-toolbar input[type="search"] {
        min-width: 0;
        flex: 1;
        height: 2.45rem;
    }

    .home-search-toolbar .btn {
        height: 2.45rem;
        padding: 0 0.95rem;
    }

    .home-add-btn {
        flex-shrink: 0;
        white-space: nowrap;
        height: 2.45rem;
        padding: 0 1rem;
    }

    .sr-only {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }

    .chat-turn {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }

    .chat-bubble {
        max-width: 85%;
        border: 1px solid var(--border);
        border-radius: 10px;
        padding: 0.6rem 0.75rem;
        font-size: 0.875rem;
    }

    .chat-user {
        align-self: flex-end;
        background: var(--primary);
        color: white;
        border-color: var(--primary);
    }

    .chat-assistant {
        align-self: flex-start;
        background: var(--bg-card);
        color: var(--text);
    }

    .search-summary {
        border: 1px solid var(--border);
        border-radius: 8px;
        background: var(--bg-card);
        padding: 0.45rem 0.65rem;
    }

    .search-summary-row {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
        align-items: baseline;
        font-size: 0.82rem;
        line-height: 1.35;
        color: var(--text);
    }

    .search-summary-main {
        font-size: 0.95rem;
        font-weight: 600;
        color: var(--text);
    }

    .search-summary-meta {
        color: var(--text-muted);
    }

    .reason-row {
        display: flex;
        flex-wrap: wrap;
        gap: 0.35rem;
        margin: 0.55rem 0 0.7rem;
    }

    .pill-reason {
        display: inline-flex;
        align-items: center;
        max-width: 100%;
        padding: 0.18rem 0.62rem;
        line-height: 1.2;
        background: transparent;
        border: 1px solid var(--border);
        color: var(--text-muted);
        white-space: normal;
        overflow-wrap: anywhere;
        word-break: break-word;
    }

    .search-result-card .link-meta {
        border-top: 1px solid var(--border);
        padding-top: 0.45rem;
    }

    /* Mobile tag filter (visible only on mobile, replaces hidden sidebar) */
    .mobile-tag-filter {
        display: none;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        gap: 0.4rem;
        padding-bottom: 0.5rem;
        margin-bottom: 0.75rem;
    }

    .mobile-tag-filter::-webkit-scrollbar {
        display: none;
    }

    .tag-chip {
        display: inline-flex;
        align-items: center;
        white-space: nowrap;
        flex-shrink: 0;
        padding: 0.3rem 0.7rem;
        border-radius: 9999px;
        border: 1px solid var(--border);
        font-size: 0.8rem;
        font-weight: 500;
        color: var(--text);
        background: var(--bg-card);
        transition: background 0.12s;
    }

    .tag-chip:hover {
        background: var(--border);
        text-decoration: none;
    }

    .tag-chip.active {
        background: var(--primary);
        color: white;
        border-color: var(--primary);
    }

    /* Sidebar layout */
    .layout {
        display: grid;
        grid-template-columns: 250px 1fr;
        gap: 1rem;
    }

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

    @media (max-width: 768px) {
        .sidebar {
            display: none;
        }

        .layout {
            grid-template-columns: 1fr;
        }
    }

    .sidebar {
        position: sticky;
        top: 64px;
        height: fit-content;
    }

    .sidebar-section {
        margin-bottom: 0.8rem;
    }

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

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

    .sidebar-list li {
        margin-bottom: 0.18rem;
    }

    .sidebar-list a {
        display: block;
        padding: 0.33rem 0.5rem;
        border-radius: 4px;
        color: var(--text);
        font-size: 0.845rem;
        line-height: 1.35;
    }

    .tag-count {
        font-size: 0.82em;
    }

    .sidebar-list a:hover {
        background: var(--border);
        text-decoration: none;
    }

    .sidebar-list a.active {
        background: var(--primary);
        color: white;
    }

    /* Links list */
    .links-list {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
        min-width: 0;
    }

    .link-card {
        background: var(--bg-card);
        border: 1px solid var(--border);
        border-radius: 8px;
        padding: 0.8rem;
        transition: box-shadow 0.15s;
        min-width: 0;
    }

    .link-card:hover {
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    }

    .link-header {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 1rem;
        margin-bottom: 0.5rem;
    }

    .link-header>div:first-child {
        flex: 1;
        min-width: 0;
    }

    .link-title {
        font-size: 1rem;
        font-weight: 600;
        margin: 0;
    }

    .link-title a {
        color: var(--text);
    }

    .link-title a:hover {
        color: var(--primary);
    }

    .link-url {
        font-size: 0.75rem;
        color: var(--text-muted);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        margin-bottom: 0.5rem;
    }

    .link-url a {
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .link-summary {
        color: var(--text-muted);
        font-size: 0.875rem;
        margin-bottom: 0.75rem;
    }

    .link-notes {
        margin-top: 0.5rem;
        margin-bottom: 0.75rem;
        font-size: 0.875rem;
    }

    .markdown-body p {
        margin: 0.4rem 0;
    }

    .markdown-body ul {
        margin: 0.4rem 0;
        padding-left: 1.2rem;
    }

    .markdown-body li {
        margin: 0.2rem 0;
    }

    .markdown-body h1,
    .markdown-body h2,
    .markdown-body h3,
    .markdown-body h4,
    .markdown-body h5,
    .markdown-body h6 {
        margin: 0.5rem 0 0.35rem;
        line-height: 1.35;
    }

    .markdown-body :not(pre)>code {
        background: var(--bg);
        border: 1px solid var(--border);
        border-radius: 4px;
        padding: 0.05rem 0.28rem;
        font-size: 0.82em;
    }

    .markdown-body pre {
        background: var(--bg);
        border: 1px solid var(--border);
        border-radius: 8px;
        padding: 0.8rem 0.9rem;
        margin: 0.55rem 0;
        overflow-x: auto;
    }

    .markdown-body pre code {
        background: transparent;
        border: 0;
        border-radius: 0;
        padding: 0;
        font-size: 0.86rem;
        line-height: 1.55;
    }

    .link-meta {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
        align-items: center;
    }

    .link-actions {
        display: flex;
        gap: 0.4rem;
        align-items: center;
        flex-wrap: wrap;
    }

    .action-row {
        display: flex;
        gap: 0.4rem;
        align-items: center;
        flex-wrap: wrap;
    }

    .action-row .btn {
        height: 2rem;
        padding: 0 0.75rem;
        border-radius: 8px;
        line-height: 1;
        white-space: nowrap;
    }

    .action-row .btn-small {
        height: 2rem;
        padding: 0 0.75rem;
        font-size: 0.75rem;
    }

    .action-row.align-end {
        justify-content: flex-end;
    }

    .action-row form {
        margin: 0;
        display: inline-flex;
    }

    /* Tag pills */
    .pill {
        display: inline-block;
        padding: 0.125rem 0.5rem;
        border-radius: 9999px;
        font-size: 0.75rem;
        font-weight: 500;
    }

    .pill-tag {
        background: var(--tag-bg);
        color: var(--tag-text);
    }

    /* Modal */
    .modal {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 1000;
        padding: 1rem;
    }

    .modal-content {
        background: var(--bg-card);
        border-radius: 12px;
        width: 100%;
        max-width: 600px;
        max-height: 90vh;
        overflow-y: auto;
        padding: 1.5rem;
    }

    .modal-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 1rem;
    }

    .modal-title {
        font-size: 1.25rem;
        font-weight: 600;
    }

    .modal-close {
        background: none;
        border: none;
        font-size: 1.5rem;
        cursor: pointer;
        color: var(--text-muted);
        padding: 0.25rem;
    }

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

    /* Empty state */
    .empty-state {
        text-align: center;
        padding: 3rem 1rem;
        color: var(--text-muted);
    }

    .empty-state h3 {
        margin-bottom: 0.5rem;
        color: var(--text);
    }

    .empty-state-icon {
        font-size: 2.5rem;
        color: var(--text-muted);
        opacity: 0.5;
        margin-bottom: 1rem;
        display: block;
    }

    /* Icon spacing in buttons and links */
    .btn i.fa-solid,
    .btn i.fa-brands,
    .page-title i.fa-solid,
    .sidebar-title i.fa-solid,
    .modal-title i.fa-solid,
    .edit-form-card h2 i.fa-solid,
    .detail-breadcrumb i.fa-solid {
        margin-right: 0.35em;
    }

    /* Tag list */
    .tag-list {
        list-style: none;
    }

    .tag-item {
        padding: 0.5rem 0;
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-bottom: 1px solid var(--border);
    }

    /* Utility */
    .text-muted {
        color: var(--text-muted);
    }

    .text-danger {
        color: var(--danger);
    }

    .text-small {
        font-size: 0.875rem;
    }

    .mt-1 {
        margin-top: 0.5rem;
    }

    .mt-2 {
        margin-top: 1rem;
    }

    .mb-1 {
        margin-bottom: 0.5rem;
    }

    .mb-2 {
        margin-bottom: 1rem;
    }

    /* HTMX loading indicator */
    .htmx-indicator {
        display: none;
    }

    .htmx-request .htmx-indicator {
        display: inline;
    }

    .htmx-request.htmx-indicator {
        display: inline;
    }

    /* Login page */
    .login-container {
        max-width: 400px;
        margin: 4rem auto;
        text-align: center;
    }

    .login-container h1 {
        font-size: 3rem;
        margin-bottom: 0.5rem;
    }

    .login-container p {
        color: var(--text-muted);
        margin-bottom: 2rem;
    }

    .login-actions {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
        align-items: center;
    }

    .login-actions .btn {
        width: 100%;
        justify-content: center;
    }

    .github-btn {
        background: #24292e;
        color: white;
        padding: 0.75rem 1.5rem;
        font-size: 1rem;
    }

    .github-btn:hover {
        background: #1b1f23;
    }

    .google-btn {
        background: #ffffff;
        color: #1a1a1a;
        border: 1px solid var(--border);
        padding: 0.75rem 1.5rem;
        font-size: 1rem;
    }

    .google-btn:hover {
        background: #f3f4f6;
    }

    .login-help {
        margin-top: 1.5rem;
        font-size: 0.875rem;
        color: var(--text-muted);
    }

    .login-help a {
        color: var(--primary);
    }

    /* Extension */
    .extension-link {
        display: inline-block;
        background: var(--primary);
        color: white;
        padding: 0.75rem 1.5rem;
        border-radius: 6px;
        font-weight: 500;
    }

    .extension-link:hover {
        background: var(--primary-hover);
        text-decoration: none;
    }

    pre {
        background: var(--bg);
        border: 1px solid var(--border);
        border-radius: 6px;
        padding: 1rem;
        overflow-x: auto;
        font-size: 0.875rem;
    }

    code {
        font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    }

    @media (max-width: 900px) {
        .sidebar {
            position: static;
        }
    }

    @media (max-width: 768px) {
        .container {
            padding: 0 0.75rem;
        }

        header .container {
            flex-direction: column;
            align-items: stretch;
            gap: 0.45rem;
        }

        .logo-cluster {
            align-items: center;
        }

        nav {
            justify-content: flex-start;
            gap: 0.6rem 0.9rem;
        }

        .chat-input-row {
            flex-direction: column;
        }

        .chat-input-row .btn {
            width: 100%;
        }

        .mobile-tag-filter {
            display: flex;
        }

        .home-controls {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 0.6rem;
        }

        .home-search-toolbar {
            display: contents;
        }

        .home-search-toolbar input[type="search"] {
            grid-column: 1 / -1;
        }

        .home-search-toolbar .btn {}

        .home-add-btn {}

        .page-header {
            align-items: stretch;
        }

        .page-header .btn {
            width: 100%;
        }

        .link-header {
            flex-direction: column;
            gap: 0.6rem;
        }

        .link-actions {
            width: 100%;
            justify-content: flex-start;
            flex-wrap: wrap;
        }

        /* Larger touch targets on mobile */
        .action-row .btn,
        .action-row .btn-small {
            min-height: 2.5rem;
            font-size: 0.875rem;
        }

        .modal-close {
            min-width: 2.5rem;
            min-height: 2.5rem;
        }
    }

    /* ---------- Export page ---------- */
    .export-doc-list {
        margin: 0.5rem 0 0 1.2rem;
        line-height: 1.7;
    }

    .export-schema {
        background: var(--bg-card);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        padding: 1rem;
        overflow-x: auto;
        font-size: 0.85rem;
        line-height: 1.5;
    }