/* Component-level aliases onto the theme tokens in base/theme.css.
   Rules below refer to these names (kept from the original stylesheets so
   the markup and rules stay recognizable); the actual values all come from
   the theme, so re-theming never means touching a component rule. */
:root {
    --topnav-primary: var(--accent);
    --topnav-text: var(--text-body);
    --topnav-text-secondary: var(--text-muted);
    --topnav-bg: var(--surface-chrome);
    --topnav-bg-secondary: var(--surface-hover);
    --topnav-border: var(--border);
    --topnav-shadow: var(--shadow-sm);
    --topnav-shadow-lg: var(--shadow-lg);

    /* Shared by the tools (see base/theme.css for what they mean) */
    --color-one: var(--data-one);
    --color-zero: var(--data-zero);
    --bg-control: var(--surface-sunken);
    --flash-success: var(--data-flash-ok);
    --flash-error: var(--data-flash-err);
    --shadow: var(--shadow-md);
    --main-font-size: clamp(0.8rem, 2.5vw, 3rem);
    --box-padding: 0.75rem;
    --font-nomono: var(--font-body);
    --card-radius: var(--radius-card);
}

html {
    /* Always reserve the vertical scrollbar's width, even on short pages,
       so the centered .topnav-wrapper doesn't shift a few pixels between
       tool pages of different heights. */
    overflow-y: scroll;
}

body {
    font-family: var(--font-nomono);
    background: var(--surface-page);
    color: var(--text-body);
    overflow-x: hidden;
}

/* Top Navigation Bar */
.topnav-container {
    background: var(--topnav-bg);
    box-shadow: var(--topnav-shadow);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.topnav-wrapper {
    max-width: 1280px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
}

.topnav-title {
    font-size: 1.875rem;
    font-weight: 700;
    font-variant: small-caps;
    margin: 0;
    color: var(--accent-title);
}

/* On tool pages the title doubles as the back-to-landing-page link */
.topnav-title a {
    color: inherit;
    text-decoration: none;
}

.topnav-title a:hover {
    text-decoration: underline;
}

/* Everything right of the title — see the comment in header.njk for why
   this exists (keeps .topnav-wrapper's own flex layout to just 2 items:
   title, this group — regardless of which of the group's own children are
   visible at a given viewport width). */
.topnav-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Desktop Menu */
.topnav-menu {
    display: flex;
    list-style: none;
    gap: 0.5rem;
}

.topnav-item {
    position: relative;
}

.topnav-link {
    display: block;
    padding: 0.5rem 1rem;
    color: var(--topnav-text);
    text-decoration: none;
    border-radius: var(--radius-control);
    transition: all 0.2s ease;
    background: transparent;
    border: none;
    font-size: 1rem;
    font-family: inherit;
    font-weight: 700;
}

.topnav-link:hover {
    background: var(--topnav-bg-secondary);
}

.topnav-link.topnav-active {
    color: var(--topnav-primary);
    background: var(--accent-soft);
}

button.topnav-link {
    cursor: pointer;
}

div.topnav-link {
    cursor: context-menu;
}

button.topnav-link:hover {
    color: var(--topnav-primary);
}

/* Dropdown */
.topnav-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 240px;
    background: var(--topnav-bg);
    border-radius: var(--radius-card);
    box-shadow: var(--topnav-shadow-lg);
    border: 1px solid var(--topnav-border);
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.2s ease;
    margin-top: 0.25rem;
}

/* Also open on keyboard focus, so the dropdowns are reachable by Tab and
   not mouse-only. */
.topnav-item:hover .topnav-dropdown,
.topnav-item:focus-within .topnav-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.topnav-dropdown-link {
    display: block;
    padding: 0.75rem 1rem;
    color: var(--topnav-text);
    text-decoration: none;
    transition: all 0.2s ease;
}

.topnav-dropdown-link:hover,
.topnav-dropdown-link:focus-visible {
    background: var(--topnav-bg-secondary);
    color: var(--topnav-primary);
    padding-left: 1.25rem;
}

.topnav-dropdown-link:first-child {
    border-radius: var(--radius-card) var(--radius-card) 0 0;
}

.topnav-dropdown-link:last-child {
    border-radius: 0 0 var(--radius-card) var(--radius-card);
}

/* Dropdown Sections */
.topnav-section-header {
    padding: 0.5rem 1rem;
    font-weight: 600;
    color: var(--topnav-text-secondary);
    font-size: 0.875rem;
    border-top: 1px solid var(--topnav-border);
}

.topnav-section-header:first-child {
    border-top: none;
}

/* Mobile Toggle */
.topnav-mobile-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
}

/* Light/dark toggle — always visible (unlike .topnav-menu / the hamburger,
   it isn't hidden at any width, since it's a small fixed-size button either
   way). Both icons are always in the DOM; only one is display:block at a
   time, based on whether .topnav-theme-toggle-dark is present. */
.topnav-theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    flex-shrink: 0;
    background: none;
    border: none;
    border-radius: var(--radius-control);
    color: var(--topnav-text);
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
}

.topnav-theme-toggle:hover {
    background: var(--topnav-bg-secondary);
    color: var(--topnav-primary);
}

.topnav-theme-icon {
    width: 20px;
    height: 20px;
}

/* Icon shown is the theme a click switches TO, not the current one — matches
   the aria-label ("Switch to dark theme" while light, etc). So: light mode
   (no .topnav-theme-toggle-dark) shows the moon, dark mode shows the sun. */
.topnav-theme-icon-sun {
    display: none;
}

.topnav-theme-toggle-dark .topnav-theme-icon-moon {
    display: none;
}

.topnav-theme-toggle-dark .topnav-theme-icon-sun {
    display: block;
}

.topnav-hamburger {
    display: block;
    width: 24px;
    height: 24px;
    position: relative;
}

.topnav-hamburger span {
    display: block;
    width: 100%;
    height: 2px;
    background: var(--topnav-text);
    position: absolute;
    left: 0;
    transition: all 0.3s ease;
}

.topnav-hamburger span:nth-child(1) {
    top: 6px;
}

.topnav-hamburger span:nth-child(2) {
    top: 11px;
}

.topnav-hamburger span:nth-child(3) {
    top: 16px;
}

.topnav-mobile-toggle.topnav-active .topnav-hamburger span:nth-child(1) {
    transform: rotate(45deg);
    top: 11px;
}

.topnav-mobile-toggle.topnav-active .topnav-hamburger span:nth-child(2) {
    opacity: 0;
}

.topnav-mobile-toggle.topnav-active .topnav-hamburger span:nth-child(3) {
    transform: rotate(-45deg);
    top: 11px;
}

/* Mobile Sidebar */
.topnav-mobile-sidebar {
    position: fixed;
    top: 0;
    right: -100%;
    width: 280px;

    /* Three fallbacks for one property: plain % (widest support), then
       100vh (standard viewport unit), then the newer -webkit-fill-available
       (iOS Safari) and stretch (future browsers) — each overrides the
       previous where it's supported, browsers ignore the ones they don't
       recognize. */
    height: 100%;
    height: 100vh;
    height: -webkit-fill-available;
    height: stretch;
    overflow: hidden;

    background: var(--topnav-bg);
    box-shadow: var(--topnav-shadow-lg);
    transition: right 0.3s ease;
    z-index: 1001;
    display: flex;
    flex-direction: column;
}

.topnav-mobile-sidebar.topnav-active {
    right: 0;
}

.topnav-mobile-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--topnav-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    background: var(--topnav-bg);
    z-index: 10;
    flex-shrink: 0;
}

.topnav-mobile-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--topnav-text);
}

.topnav-mobile-close {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    z-index: 15;
}

.topnav-mobile-nav {
    padding: 1rem;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1 1 auto;
    /* 70px ≈ .topnav-mobile-header's rendered height, so this fills exactly
       the space left below it rather than overflowing the sidebar. */
    max-height: calc(100% - 70px);
}

.topnav-mobile-item {
    margin-bottom: 0.25rem;
}

.topnav-mobile-link {
    display: block;
    padding: 0.75rem 1rem;
    color: var(--topnav-text);
    text-decoration: none;
    border-radius: var(--radius-control);
    transition: all 0.2s ease;
    font-weight: 700;
}

.topnav-mobile-link:hover {}

div.topnav-mobile-link:hover {
    cursor: context-menu;
    background: var(--surface-hover);
}

a.topnav-mobile-link:hover {
    background: var(--topnav-bg-secondary);
    color: var(--topnav-primary);

}

/* Info sits first in the mobile sidebar (see partials/header.njk) and is
   tinted + rule-separated so the tool's instructions read as their own thing
   rather than as one more menu heading in the list below it. */
.topnav-mobile-item-info {
    margin-bottom: 0.75rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--topnav-border);
}

.topnav-mobile-item-info .topnav-mobile-link {
    background: var(--accent-soft);
    color: var(--topnav-primary);
}

.topnav-mobile-submenu {
    padding-left: 1.5rem;
    margin-top: 0.25rem;
}

.topnav-mobile-submenu-label {
    border-radius: var(--radius-control);
    padding: 0.5rem 1rem;
    font-weight: 600;
    color: var(--topnav-text-secondary);
    font-size: 0.875rem;
    cursor: context-menu;
}

.topnav-mobile-submenu-label:hover {
    background: var(--surface-hover);

}

.topnav-mobile-sublink {
    display: block;
    padding: 0.5rem 1rem;
    color: var(--topnav-text-secondary);
    text-decoration: none;
    font-size: 0.875rem;
    transition: all 0.2s ease;
    border-radius: var(--radius-control);
}

.topnav-mobile-sublink:hover {
    color: var(--topnav-primary);
    background: var(--topnav-bg-secondary);
}

/* Info Overlay */
.topnav-info-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--overlay-scrim);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.topnav-info-overlay.topnav-show {
    display: flex;
    opacity: 1;
}

.topnav-info-box {
    background: var(--topnav-bg);
    border-radius: var(--radius-card);
    box-shadow: var(--topnav-shadow-lg);
    max-width: 700px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.topnav-info-overlay.topnav-show .topnav-info-box {
    transform: scale(1);
}

.topnav-info-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--topnav-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.topnav-info-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--topnav-text);
}

.topnav-info-close {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    color: var(--topnav-text-secondary);
}

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

.topnav-info-content {
    padding: 1.5rem;
    color: var(--topnav-text-secondary);
    line-height: 1.5;
    margin-bottom: 1rem;
    text-align: left;
}

.topnav-info-content h3 {
    padding: 1rem 0rem 0.5rem 0rem;
}

.topnav-info-content p {
    padding: 0.5rem 0rem;
}

.topnav-info-content ul {
    padding-left: 1.5rem;
}

.topnav-info-content li {
    margin-bottom: 0.5rem;
}

/* Inline keycap chip. Kept narrow by default so single-character keys used
   in body copy (e.g. SubnetIPv4's "press . or / to jump") render as tight
   chips; only the info overlay's shortcut list widens them to line up as a
   column. */
.key {
    font-family: var(--font-mono);
    background-color: var(--topnav-bg-secondary);
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    display: inline-block;
    text-align: center;
}

.topnav-info-content .key {
    min-width: 6ch;
}

.topnav-info-content a {
    color: var(--topnav-primary);
    text-decoration: none;
}

.topnav-info-content a:hover {
    text-decoration: underline;
}

/* Responsive */
@media (max-width: 768px) {
    .topnav-wrapper {
        padding: 0.5rem 1.5rem;
    }

    .topnav-menu {
        display: none;
    }

    .topnav-mobile-toggle {
        display: block;
    }

    .topnav-title {
        font-size: 1.5rem;
    }

    .topnav-info-header,
    .topnav-info-content {
        padding: 0.75rem;
    }

    .topnav-info-content h3 {
        padding: 1rem 0rem 0.3rem 0rem;
    }

    .topnav-info-content p {
        padding: 0.3rem 0rem;
    }

    .topnav-info-content ul {
        padding-left: 1.5rem;
    }

    .topnav-info-content li {
        margin-bottom: 0.5rem;
    }
}
