/**
 * Directive Viewer Styles
 *
 * Technical styling for instruction directives with improved readability.
 * Functional design focused on clarity and technical precision.
 */

/* Better font stack for readability */
:root {
    --font-mono: 'SF Mono', 'Monaco', 'Menlo', 'Consolas', 'Liberation Mono', monospace;
    --font-system: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
}

/* Main directive container */
.directive-container {
    background: var(--fallback-b1, var(--color-bg-1));
    border: 1px solid var(--fallback-bc, rgba(31, 41, 55, 0.2));
    border-radius: 0.5rem;
    overflow: hidden;
}

/* Frontmatter display - visible, minimal */
.frontmatter-display {
    background: var(--fallback-b2, var(--color-bg-2));
    border-bottom: 1px solid var(--fallback-bc, rgba(31, 41, 55, 0.2));
    font-family: var(--font-mono);
}

.frontmatter-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--fallback-b3, var(--color-bg-3));
    border-bottom: 1px solid var(--fallback-bc, rgba(31, 41, 55, 0.1));
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    color: var(--fallback-bc, rgba(31, 41, 55, 0.6));
}

.frontmatter-body {
    padding: 0.75rem 1rem;
    display: grid;
    gap: 0.25rem;
}

.frontmatter-item {
    display: flex;
    gap: 0.5rem;
    font-size: 0.8125rem;
    line-height: 1.5;
}

.frontmatter-key {
    color: var(--fallback-bc, rgba(31, 41, 55, 0.5));
    font-weight: 500;
    min-width: 100px;
}

.frontmatter-value {
    color: var(--fallback-bc, rgba(31, 41, 55, 0.9));
}

/* Content with TOC layout */
.content-with-toc {
    display: grid;
    grid-template-columns: 1fr 250px;
    gap: 2rem;
    min-height: 100%;
}

@media (max-width: 1280px) {
    .content-with-toc {
        grid-template-columns: 1fr;
    }

    .toc-sidebar {
        display: none !important;
    }
}

/* Main directive content - improved readability */
.directive-content {
    padding: 2rem;
    font-family: var(--font-system);
    font-size: 0.9375rem;
    line-height: 1.7;
    color: var(--fallback-bc, rgba(31, 41, 55, 0.9));
    min-width: 0; /* Prevent grid blowout */
}

/* TOC Sidebar */
.toc-sidebar {
    padding: 2rem 1rem 2rem 0;
    font-size: 0.8125rem;
}

.toc-sticky {
    position: sticky;
    top: 2rem;
    max-height: calc(100vh - 4rem);
    overflow-y: auto;
}

.toc-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--fallback-bc, rgba(31, 41, 55, 0.5));
    margin-bottom: 1rem;
}

.toc-links ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.toc-links ul ul {
    padding-left: 1rem;
    margin-top: 0.25rem;
}

.toc-links a {
    display: block;
    padding: 0.375rem 0.5rem;
    color: var(--fallback-bc, rgba(31, 41, 55, 0.7));
    text-decoration: none;
    border-left: 2px solid transparent;
    transition: all 0.15s ease;
    line-height: 1.4;
}

.toc-links a:hover {
    color: var(--fallback-p, var(--color-primary));
    border-left-color: var(--fallback-p, rgba(34, 211, 238, 0.3));
    background: var(--fallback-p, rgba(34, 211, 238, 0.05));
}

.toc-links a:active,
.toc-links a:focus {
    border-left-color: var(--fallback-p, var(--color-primary));
    background: var(--fallback-p, rgba(34, 211, 238, 0.1));
}

/* Headings - smaller, no separators */
.directive-content h1,
.directive-content h2,
.directive-content h3,
.directive-content h4,
.directive-content h5,
.directive-content h6 {
    font-family: var(--font-system);
    font-weight: 600;
    letter-spacing: -0.015em;
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    color: var(--fallback-bc, rgba(31, 41, 55, 1));
}

.directive-content h1 {
    font-size: 1.25rem;
}

.directive-content h2 {
    font-size: 1.125rem;
}

.directive-content h3 {
    font-size: 1rem;
}

.directive-content h4 {
    font-size: 0.9375rem;
    color: var(--fallback-bc, rgba(31, 41, 55, 0.8));
}

/* Show all h1 titles in content */

/* Paragraphs */
.directive-content p {
    margin-bottom: 1rem;
}

/* Lists - technical formatting */
.directive-content ul,
.directive-content ol {
    margin-left: 1.5rem;
    margin-bottom: 1rem;
}

.directive-content li {
    margin-bottom: 0.25rem;
}

.directive-content ul {
    list-style-type: disc;
}

.directive-content ol {
    list-style-type: decimal;
}

/* Code blocks - terminal style */
.directive-content pre {
    background: var(--fallback-b3, var(--color-bg-3));
    border: 1px solid var(--fallback-bc, rgba(31, 41, 55, 0.2));
    border-left: 3px solid var(--fallback-p, var(--color-primary));
    padding: 1rem;
    margin: 1rem 0;
    overflow-x: auto;
    font-size: 0.8125rem;
    line-height: 1.5;
}

.directive-content code {
    font-family: var(--font-mono);
    background: var(--fallback-b3, var(--color-bg-3));
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    font-size: 0.875em;
}

.directive-content pre code {
    background: transparent;
    padding: 0;
}

/* Blockquotes - directive style */
.directive-content blockquote {
    border-left: 3px solid var(--fallback-bc, rgba(31, 41, 55, 0.3));
    padding-left: 1rem;
    margin: 1rem 0;
    color: var(--fallback-bc, rgba(31, 41, 55, 0.7));
    font-style: italic;
}

/* Tables - technical grid */
.directive-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
    font-size: 0.8125rem;
}

.directive-content th,
.directive-content td {
    border: 1px solid var(--fallback-bc, rgba(31, 41, 55, 0.2));
    padding: 0.5rem 0.75rem;
    text-align: left;
}

.directive-content th {
    background: var(--fallback-b2, var(--color-bg-2));
    font-weight: 600;
    letter-spacing: 0.025em;
}

.directive-content tr:nth-child(even) {
    background: var(--fallback-b2, oklch(var(--b2) / 0.5));
}

/* Horizontal rule */
.directive-content hr {
    border: none;
    border-top: 1px solid var(--fallback-bc, rgba(31, 41, 55, 0.2));
    margin: 2rem 0;
}

/* Instruction links - highlighted clickable style */
.directive-content .instruction-link {
    color: var(--fallback-p, var(--color-primary));
    text-decoration: none;
    font-weight: 600;
    padding: 0.125rem 0.25rem;
    border-radius: 0.25rem;
    background: var(--fallback-p, rgba(34, 211, 238, 0.1));
    transition: all 0.15s ease;
}

.directive-content .instruction-link:hover {
    background: var(--fallback-p, rgba(34, 211, 238, 0.2));
    text-decoration: underline;
}

/* Code-style instruction links (in backticks) */
.directive-content .code-link {
    font-family: var(--font-mono);
    font-size: 0.9em;
    font-weight: 500;
}

/* Links */
.directive-content a:not(.instruction-link) {
    color: var(--fallback-bc, rgba(31, 41, 55, 0.7));
    text-decoration: underline;
}

.directive-content a:not(.instruction-link):hover {
    color: var(--fallback-p, var(--color-primary));
}

/* Strong and emphasis */
.directive-content strong {
    font-weight: 700;
    color: var(--fallback-bc, rgba(31, 41, 55, 1));
}

.directive-content em {
    font-style: italic;
}

/* Images */
.directive-content img {
    max-width: 100%;
    height: auto;
    margin: 1rem 0;
    border: 1px solid var(--fallback-bc, rgba(31, 41, 55, 0.2));
    border-radius: 0.25rem;
}

/* Advanced panel styling */
#advancedPanel {
    animation: slideDown 0.2s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Sidebar Navigation */
.directive-layout {
    display: flex;
    gap: 0;
}

.directive-sidebar {
    width: 280px;
    flex-shrink: 0;
    background: var(--fallback-b2, var(--color-bg-2));
    border-right: 1px solid var(--fallback-bc, rgba(31, 41, 55, 0.2));
}

.directive-main {
    flex: 1;
    min-width: 0;
}

.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid var(--fallback-bc, rgba(31, 41, 55, 0.1));
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    color: var(--fallback-bc, rgba(31, 41, 55, 0.6));
    background: var(--fallback-b3, var(--color-bg-3));
}

.sidebar-nav {
    padding: 0.5rem;
}

.nav-item {
    margin-bottom: 0.125rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-family: var(--font-system);
    color: var(--fallback-bc, rgba(31, 41, 55, 0.7));
    text-decoration: none;
    transition: all 0.15s ease;
}

.nav-link:hover {
    background: var(--fallback-b3, var(--color-bg-3));
    color: var(--fallback-bc, rgba(31, 41, 55, 1));
}

.nav-link.active {
    background: var(--fallback-p, rgba(34, 211, 238, 0.15));
    color: var(--fallback-p, var(--color-primary));
    font-weight: 600;
}

.nav-link.main-instruction {
    font-weight: 600;
    color: var(--fallback-bc, rgba(31, 41, 55, 0.9));
}

.nav-icon {
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
}

.nav-children {
    margin-left: 1.5rem;
    margin-top: 0.125rem;
    border-left: 1px solid var(--fallback-bc, rgba(31, 41, 55, 0.15));
    padding-left: 0.5rem;
}

.nav-children .nav-link {
    font-size: 0.8125rem;
    padding: 0.375rem 0.75rem;
}

.nav-toggle {
    cursor: pointer;
    padding: 0.125rem;
    border-radius: 0.25rem;
    transition: transform 0.15s ease;
}

.nav-toggle:hover {
    background: var(--fallback-bc, rgba(31, 41, 55, 0.1));
}

.nav-toggle.collapsed {
    transform: rotate(-90deg);
}

/* Metadata Header */
.metadata-header {
    background: var(--fallback-b2, var(--color-bg-2));
    border: 1px solid var(--fallback-bc, rgba(31, 41, 55, 0.2));
    border-radius: 0.5rem;
    margin-bottom: 1.5rem;
    padding: 1rem;
}

.metadata-body {
    /* No extra padding, parent has it */
}

/* Content wrapper - aligned with sidebar */
.directive-content-wrapper {
    padding: 0 1.5rem;  /* Horizontal padding only, no top/bottom */
}

.directive-content-wrapper .metadata-header {
    margin-top: 0;  /* Remove extra top margin */
    margin-bottom: 1rem;  /* Reduce space before content */
}

.directive-content-wrapper .directive-container {
    margin-top: 0;  /* Remove extra padding in content block */
}

.directive-content h1:first-child,
.directive-content h2:first-child {
    margin-top: 0;  /* Remove top margin from first heading */
}

/* Responsive adjustments */
@media (max-width: 1024px) {
    .directive-sidebar {
        width: 240px;
    }
}

@media (max-width: 768px) {
    .directive-layout {
        flex-direction: column;
    }

    .directive-sidebar {
        width: 100%;
        position: static;
        max-height: none;
        border-right: none;
        border-bottom: 1px solid var(--fallback-bc, rgba(31, 41, 55, 0.2));
    }

    .directive-content-wrapper {
        padding: 0 1rem;  /* Smaller horizontal padding on mobile */
    }

    .directive-content {
        padding: 1rem;
        font-size: 0.8125rem;
    }

    .directive-content h1 {
        font-size: 1.25rem;
    }

    .directive-content h2 {
        font-size: 1.125rem;
    }

    .directive-content h3 {
        font-size: 1rem;
    }
}

/* Dark mode overrides for navigation sidebars */
[data-theme="dark"] .sidebar-header {
    color: rgb(209, 213, 219);
    border-bottom-color: rgb(75, 85, 99);
    background: rgb(17, 24, 39);
}

[data-theme="dark"] .nav-link {
    color: rgb(229, 231, 235);
}

[data-theme="dark"] .nav-link:hover {
    background: rgb(55, 65, 81);
    color: rgb(255, 255, 255);
}

[data-theme="dark"] .nav-link.active {
    background: rgba(34, 211, 238, 0.2);
    color: rgb(103, 232, 249);
}

[data-theme="dark"] .nav-link.main-instruction {
    color: rgb(249, 250, 251);
}

[data-theme="dark"] .directive-sidebar {
    background: rgb(17, 24, 39);
    border-right-color: rgb(75, 85, 99);
}

[data-theme="dark"] .nav-children {
    border-left-color: rgb(75, 85, 99);
}

[data-theme="dark"] .toc-sidebar {
    background: rgb(17, 24, 39);
    border-left-color: rgb(75, 85, 99);
}

[data-theme="dark"] .nav-item {
    color: rgb(229, 231, 235);
}

[data-theme="dark"] .nav-item:hover {
    background: rgb(55, 65, 81);
    color: rgb(255, 255, 255);
}
