/* ==========================================================================
   Variables
   ========================================================================== */
:root {
    /* Colors */
    --bg: #f5f5f5;
    --bg-secondary: #eee;
    --card: #fff;
    --backdrop: rgba(0, 0, 0, 0.5);

    --text: #222;
    --text-secondary: #666;
    --text-placeholder: #757575;
    --text-white: #fff;
    --muted: #6f6f6f;

    --accent: #111;

    --border: #dcdcdc;
    --border-light: #e0e0e0;
    --border-table: #ddd;
    --hr: #bdc3c7;

    --error: #d32f2f;

    /* Shell */
    --bg-shell: #f0f0f0;
    --bg-shell-input: rgba(0, 0, 0, 0.03);
    --shell-prompt: #8e85d6;
    --shell-selection: rgba(142, 133, 214, 0.4);

    /* Spacing */
    --spacing-sm: 8px;
    --spacing-md: 12px;
    --spacing-lg: 20px;
    --spacing-xl: 24px;

    /* Typography */
    --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", sans-chinese, monospace;
    --font-size-sm: 0.9rem;
    --font-size-xl: 2rem;

    /* Borders */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-pill: 999px;
}

/* ==========================================================================
   Reset & Base
   ========================================================================== */
* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font-mono);
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
    scrollbar-gutter: stable both-edges;

    &[content-modal-locked="true"] {
        overflow: hidden;
    }
}

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

    &:visited {
        color: var(--text);
        text-decoration: none;
    }

    &:hover {
        text-decoration: none;
    }
}

hr {
    border: 0;
    border-top: 1px solid var(--hr);
    margin: 5px 0;
}

/* ==========================================================================
   Layout
   ========================================================================== */
.hero {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    padding: var(--spacing-xl) 0 48px;

    .container {
        text-align: left;
        width: 90%;
        max-width: 1200px;
        margin: 0 auto;
        display: flex;
        flex-direction: column;
    }

    .title {
        text-align: left;
        margin: 0 0 var(--spacing-md) 0;
        font-size: var(--font-size-xl);
        align-self: stretch;
        position: sticky;
        top: 0;
        padding: 16px 0 8px;
        background: var(--bg);
        border-bottom: 1px solid var(--border-light);
        z-index: 10;
    }
}

.title-flex {
    display: flex;
    align-items: baseline;
    gap: 10px;
    flex-wrap: wrap;
}

.title-footnote {
    font-size: 0.8rem;
    font-weight: normal;
    color: var(--text-secondary);
}

.title-link {
    color: inherit;
    text-decoration: none;
    margin-left: 0 !important;
    font-size: inherit !important;
}

.route-dropdown {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.route-dropdown__toggle {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: transparent;
    border: none;
    color: inherit;
    font: inherit;
    padding: 2px 6px;
    cursor: pointer;
    text-decoration: underline dotted;
}

.route-dropdown__toggle:focus-visible {
    outline: 1px dashed var(--text-secondary);
    outline-offset: 2px;
}

.route-dropdown__menu {
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 80px;
    background: var(--bg-secondary);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
    display: none;
    z-index: 20;
}

.route-dropdown--open .route-dropdown__menu,
.route-dropdown:focus-within .route-dropdown__menu,
.route-dropdown:hover .route-dropdown__menu {
    display: block;
}

.route-dropdown__list,
.route-dropdown__sub {
    list-style: none;
    padding: 0;
    margin: 0;
}

.route-dropdown__item {
    position: relative;
}

.route-dropdown__link,
.route-dropdown__label {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    padding: 8px 16px;
    color: var(--text);
    text-decoration: none;
    font-size: 0.85rem;
    white-space: nowrap;
    min-width: 80px;
    min-height: 32px;
    line-height: 1.2;
    transition: background 0.15s ease, color 0.15s ease;
    user-select: none;
    -webkit-user-select: none;
    width: 100%;
}

.route-dropdown__label {
    cursor: pointer;
    font-weight: inherit;
}

.route-dropdown__item.has-children>.route-dropdown__label {
    padding-right: 32px;
}

.route-dropdown__item:hover>.route-dropdown__link,
.route-dropdown__item:focus-within>.route-dropdown__link,
.route-dropdown__item:hover>.route-dropdown__label,
.route-dropdown__item:focus-within>.route-dropdown__label {
    background: rgba(0, 0, 0, 0.08);
}

.route-dropdown__item.is-active>.route-dropdown__link,
.route-dropdown__item.is-active>.route-dropdown__label,
.route-dropdown__sub-item.is-active>.route-dropdown__sub-link {
    background: rgba(0, 0, 0, 0.14);
    font-weight: 600;
}

.route-dropdown__sub-item:hover>.route-dropdown__sub-link,
.route-dropdown__sub-item:focus-within>.route-dropdown__sub-link,
.route-dropdown__sub-link:hover,
.route-dropdown__sub-link:focus-visible {
    background: rgba(0, 0, 0, 0.08);
}

.route-dropdown__item:first-child>.route-dropdown__link,
.route-dropdown__item:first-child>.route-dropdown__label {
    border-top-left-radius: var(--radius-md);
    border-top-right-radius: var(--radius-md);
}

.route-dropdown__item:last-child>.route-dropdown__link,
.route-dropdown__item:last-child>.route-dropdown__label {
    border-bottom-left-radius: var(--radius-md);
    border-bottom-right-radius: var(--radius-md);
}

.route-dropdown__sub-item:first-child>.route-dropdown__sub-link {
    border-top-left-radius: var(--radius-md);
    border-top-right-radius: var(--radius-md);
}

.route-dropdown__sub-item:last-child>.route-dropdown__sub-link {
    border-bottom-left-radius: var(--radius-md);
    border-bottom-right-radius: var(--radius-md);
}

.route-dropdown__sub {
    position: absolute;
    top: 0;
    left: calc(100% - 2px);
    margin-left: 0;
    background: var(--bg-secondary);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
    display: none;
}

.route-dropdown__item:hover>.route-dropdown__sub,
.route-dropdown__item:focus-within>.route-dropdown__sub {
    display: block;
}

.route-dropdown__sub.opens-left {
    left: auto;
    right: 100%;
    margin-left: 0;
    margin-right: 0;
}

.route-dropdown__menu {
    left: -4px;
}

.route-dropdown__sub {
    left: 100%;
    margin-left: 0;
}

.route-dropdown__sub-link {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    color: var(--text);
    text-decoration: none;
    font-size: 0.8rem;
    white-space: nowrap;
    min-height: 32px;
    line-height: 1.2;
    transition: background 0.15s ease, color 0.15s ease;
    user-select: none;
    -webkit-user-select: none;
    width: 100%;
}

/* ==========================================================================
   Components
   ========================================================================== */

/* Peering Page */
.peering {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xl);
    font-size: var(--font-size-sm);
}

.peering-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--spacing-lg);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.peering-card-header {
    margin-bottom: var(--spacing-md);
}

.peering-card-title {
    margin: 0 0 4px;
    font-size: 1.1rem;
    letter-spacing: 0.01em;
}

.peering-card-subtitle {
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.85em;
}

.peering-node-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-lg);
}

.peering-node-header {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.peering-node-title {
    margin: 0;
    font-size: 1rem;
}

.peering-node-meta {
    font-size: 0.85em;
    color: var(--text-secondary);
}

.peering-grid {
    display: grid;
    grid-template-columns: minmax(120px, 200px) minmax(0, 1fr);
    gap: 6px 16px;
    margin: 0;
}

.peering-label {
    font-weight: 600;
    color: var(--text-secondary);
}

.peering-value {
    margin: 0;
    text-align: right;
    font-family: var(--font-mono);
    word-break: break-all;
    color: var(--text);
    cursor: pointer;
}

.peering-empty {
    text-align: center;
    padding: 48px 0;
    color: var(--text-secondary);
}

.peering-contact-grid {
    grid-template-columns: minmax(110px, 160px) minmax(0, 1fr);
    gap: 8px 20px;
}

.peering-contact-label {
    letter-spacing: 0.05em;
    text-transform: uppercase;
    font-size: 0.75rem;
}

.peering-contact-value {
    text-align: left;
    font-family: inherit;
    word-break: break-word;
    white-space: normal;
}


/* Status Messages */
.status-message {
    margin-bottom: 15px;
    font-size: 0.9em;
    color: var(--text-secondary);

    &--error {
        color: var(--error);
    }
}

.error-message {
    margin-top: -10px;
    margin-bottom: 20px;
    color: var(--error);
    font-size: 0.9em;
}

.status-pill {
    display: inline-block;
    padding: 1px 6px;
    background: var(--error);
    color: var(--text-white);
    border-radius: var(--radius-pill);
    font-size: 0.7em;
    text-transform: uppercase;
}

/* Expandable Items */
.expandable-item {
    margin-bottom: var(--spacing-lg);
}

.summary-header {
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex-wrap: wrap;
    cursor: pointer;
    padding: 4px 0;
    list-style: none;

    &::-webkit-details-marker {
        display: none;
    }

    &::before {
        content: "▶";
        display: inline-block;
        font-size: 0.8em;
        transition: transform 0.2s;
        margin-right: 4px;
    }
}

details[open] {
    .summary-header::before {
        transform: rotate(90deg);
    }

    .summary-header {
        margin-bottom: 10px;
    }
}

.item-title {
    font-size: 1.1em;
    font-weight: 600;
    margin: 0;
}

.item-meta {
    font-size: 0.8em;
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

/* Data Tables */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9em;

    th {
        padding: var(--spacing-sm);
        background: var(--bg-secondary);
        text-align: left;
    }

    td {
        padding: var(--spacing-sm);
        border-bottom: 1px solid var(--border-table);
    }
}

.clickable-row {
    cursor: pointer;
}

/* Shell Component */
.shell-line {
    display: block;
    font-family: monospace;
    background: var(--bg-shell);
    padding: 10px;
    border-radius: var(--radius-sm);
    margin-bottom: 10px;
    border: 1px solid var(--border);
    white-space: pre-wrap;
    word-break: break-all;
}

.shell-prompt {
    color: var(--shell-prompt);
    font-weight: bold;
    white-space: pre-wrap;
}

.shell-select {
    background: transparent;
    border: none;
    font-family: monospace;
    font-size: 1em;
    color: inherit;
    font-weight: inherit;
    padding: 0;
    outline: none;
    caret-color: transparent;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    border-bottom: 1px dotted var(--text);
    user-select: text;
    -webkit-user-select: text;

    &:focus-visible {
        outline: 1px dotted var(--text);
    }
}

.shell-input-wrapper {
    display: inline;
    position: relative;
    border-radius: 2px;
    background: var(--bg-shell-input);
    cursor: text;

    &:focus-within {
        .shell-cursor-char {
            position: relative;
            text-decoration: none;

            &::after {
                content: '';
                position: absolute;
                left: 0;
                bottom: 0;
                width: 100%;
                height: 1px;
                background-color: var(--text);
                animation: blink 1s step-end infinite;
            }
        }
    }
}

.shell-input-content {
    font-family: monospace;
    font-size: 1em;
    white-space: pre-wrap;
    word-break: break-all;
    color: var(--text);
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;

    -webkit-text-autocorrect: none;
    -webkit-autocapitalize: none;
    -webkit-user-modify: read-write-plaintext-only;
    -webkit-text-size-adjust: none;

    &.placeholder {
        color: var(--text-placeholder);
        user-select: none;
        -webkit-user-select: none;
    }
}

.shell-input-hidden {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: text;
    padding: 0;
    border: none;
    margin: 0;
    font-family: monospace;
    caret-color: transparent;
    background: transparent;
    color: transparent;
    pointer-events: none;
}

.shell-input-selection {
    background-color: var(--shell-selection);
    color: var(--text);
}

.shell-button {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    font-family: monospace;
    cursor: pointer;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.9em;
    float: right;

    &:hover:not(:disabled) {
        background: var(--bg-secondary);
        border-color: var(--accent);
    }

    &:disabled {
        opacity: 0.5;
        cursor: not-allowed;
    }
}

.refresh-button {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 0.8em;
    color: var(--text-secondary);
    padding: 0 8px;
    transition: color 0.2s;

    &:hover {
        color: var(--text);
    }
}

.shell-toggle {
    font-family: monospace;
    font-size: 1em;
    cursor: pointer;
    color: var(--muted);
    opacity: 0.4;
    user-select: none;
    -webkit-user-select: none;
    transition: all 0.2s;
    text-decoration: line-through;

    &.active {
        color: var(--text);
        opacity: 1;
        font-weight: normal;
        text-decoration: none;
        user-select: text;
        -webkit-user-select: text;
    }

    &:hover {
        opacity: 0.8;
    }
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}

/* Modals */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--backdrop);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.modal-content {
    background: var(--card);
    padding: 5px;
    border-radius: var(--radius-md);
    max-width: 800px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;

    pre {
        background: var(--bg);
        padding: 10px;
        overflow-x: auto;
        margin: 2px;
    }
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 720px) {
    .hero {
        padding: 20px 0 32px;
    }

    .peering-card {
        padding: var(--spacing-md);
    }

    .peering-grid {
        grid-template-columns: minmax(100px, 1fr) minmax(0, 1fr);
        gap: 4px 10px;
    }

    .peering-value {
        text-align: left;
        word-break: break-word;
    }

    .data-table {
        border-collapse: separate;

        thead {
            display: none;
        }

        tbody {
            display: flex;
            flex-direction: column;
            gap: 12px;
        }

        tr {
            display: grid;
            grid-template-columns: repeat(2, minmax(0, 1fr));
            gap: 8px;
            padding: 12px;
            border: 1px solid var(--bg-secondary);
            border-radius: 10px;
            background: var(--card);
        }

        td {
            display: flex;
            flex-direction: column;
            padding: 0;
            border: none;
            font-size: 0.85rem;
            gap: 2px;

            &::before {
                content: attr(data-label);
                font-size: 0.7rem;
                font-weight: 600;
                text-transform: uppercase;
                color: var(--muted);
                letter-spacing: 0.04em;
            }
        }
    }
}

/* ==========================================================================
   Auto Peer Page
   ========================================================================== */
.autopeer {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xl);
    font-size: var(--font-size-sm);
}

.autopeer-container {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-lg);
}

.autopeer-step {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
}

.autopeer-challenge-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    margin-left: var(--spacing-lg);
}

.autopeer-method-desc {
    color: var(--text-secondary);
    font-size: 0.85em;
    margin-left: var(--spacing-sm);
}

.autopeer-challenge-text {
    background: var(--bg-shell);
    padding: var(--spacing-md);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    margin: var(--spacing-sm) 0;
}

.autopeer-challenge-text pre {
    margin: 0;
    font-family: var(--font-mono);
    font-size: 0.85em;
    white-space: pre-wrap;
    word-break: break-all;
}

.autopeer-sessions {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-lg);
}

.autopeer-sessions-list {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-lg);
}

.autopeer-session-actions {
    display: flex;
    gap: var(--spacing-sm);
    margin-top: var(--spacing-md);
    justify-content: flex-end;
}

.autopeer-session-actions .shell-button {
    float: none;
}

.autopeer-session-edit {
    margin-top: var(--spacing-md);
}

.autopeer-new-session {
    margin-top: var(--spacing-xl);
    padding-top: var(--spacing-xl);
    border-top: 1px solid var(--border-light);
}

.autopeer-form {
    margin-top: var(--spacing-md);
    padding: var(--spacing-md);
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
}

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

/* DN42 Page */
.dn42-page {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xl);
    font-size: var(--font-size-sm);
    max-width: 600px;
}

.dn42-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--spacing-lg);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.dn42-visitor-card {
    background: linear-gradient(135deg, var(--card) 0%, var(--bg-secondary) 100%);
}

.dn42-visitor-line {
    margin: 0 0 6px 0;
    line-height: 1.5;
}

.dn42-visitor-line:last-child {
    margin-bottom: 0;
}

.dn42-highlight {
    font-weight: 600;
    color: var(--shell-prompt);
}

.dn42-stats-card {
    background: var(--bg-secondary);
    border-color: transparent;
}

.dn42-stats-line {
    margin: 0;
    font-size: 0.95em;
}

.dn42-links {
    display: flex;
    gap: var(--spacing-md);
    flex-wrap: wrap;
}

.dn42-link-card {
    flex: 1 1 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-md) var(--spacing-lg);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text);
    text-decoration: none;
    font-weight: 500;
    transition: all 0.15s ease;
}

.dn42-link-card:hover {
    background: var(--bg-secondary);
    border-color: var(--shell-prompt);
    color: var(--shell-prompt);
}

.dn42-info-card {
    background: var(--bg);
    border-color: var(--border-light);
}

.dn42-info-title {
    margin: 0 0 var(--spacing-sm) 0;
    font-size: 1rem;
}

.dn42-info-text {
    margin: 0 0 var(--spacing-md) 0;
    color: var(--text-secondary);
    line-height: 1.5;
}

.dn42-info-link {
    color: var(--shell-prompt);
    text-decoration: none;
    font-weight: 500;
}

.dn42-info-link:hover {
    text-decoration: underline;
}

@media (max-width: 720px) {
    .dn42-links {
        flex-direction: column;
    }

    .dn42-link-card {
        flex: 1 1 auto;
    }
}