:root {
    --color-bg: #0a0a0f;
    --color-surface: #0d1117;
    --color-green: #00ff41;
    --color-green-15: rgba(0, 255, 65, 0.15);
    --color-green-05: rgba(0, 255, 65, 0.05);
    --color-cyan: #00e5ff;
    --color-amber: #ffb000;
    --color-purple: #7c3aed;
    --color-red: #ff4757;
    --text-primary: #e6edf3;
    --text-secondary: #7d8590;
    --text-muted: #484f58;
    --font-mono: "JetBrains Mono", "Share Tech Mono", monospace;
    --radius-lg: 8px;
    --radius-xl: 12px;
    --space-4: 1rem;
    --space-6: 1.5rem;
    --glow-green: 0 0 15px rgba(0, 255, 65, 0.3);
    --glow-cyan: 0 0 12px rgba(0, 229, 255, 0.25);

    /* Layer colors for packet diagram */
    --layer-l1: #2d3436;
    --layer-l2: #00b894;
    --layer-vlan: #00cec9;
    --layer-mpls: #fdcb6e;
    --layer-overlay: #a29bfe;
    --layer-l3: #74b9ff;
    --layer-l4: #fd79a8;
    --layer-rdma: #e84393;
    --layer-storage: #ffeaa7;
    --layer-security: #ff9f43;
    --layer-other: #636e72;
}

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

body {
    background-color: var(--color-bg);
    color: var(--text-primary);
    font-family: var(--font-mono);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.app-container {
    max-width: 1100px;
    margin: 0 auto;
    padding: var(--space-6);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.pkt-size-app {
    max-width: 1200px;
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: var(--space-6);
    padding-bottom: var(--space-4);
    border-bottom: 1px solid var(--color-green-15);
}

.header-left {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.back-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.back-link:hover {
    color: var(--color-green);
}

h1 {
    font-size: 1.6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 3px;
}
h1 .accent {
    color: var(--color-green);
}

.subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    letter-spacing: 1px;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.7rem;
    color: var(--text-muted);
}
.status-indicator .dot {
    width: 6px;
    height: 6px;
    background-color: var(--color-green);
    border-radius: 50%;
    box-shadow: var(--glow-green);
}

/* === Metrics Bar === */
.metrics-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
    background: #111214;
    border: 1px solid var(--color-green-15);
    border-radius: var(--radius-xl);
    padding: 1rem 1.25rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.metric {
    text-align: center;
}
.metric-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    letter-spacing: 1px;
    margin-bottom: 0.1rem;
}
.metric-value {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--color-green);
    line-height: 1.05;
    text-shadow: 0 0 8px rgba(0, 255, 65, 0.25);
}
.metric-unit {
    font-size: 0.65rem;
    color: var(--text-secondary);
}

/* === Visual Section === */
.visual-section {
    margin-bottom: 1.5rem;
}

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

.builder-actions {
    position: relative;
}
.section-header h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1.5px;
}

.packet-visual {
    background: #0d0f14;
    border: 1px solid var(--color-green-15);
    border-radius: var(--radius-xl);
    padding: 1.5rem 1.25rem;
    min-height: 180px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow-x: auto;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.03),
        0 0 0 1px rgba(0, 255, 65, 0.05);
}

.packet-visual svg {
    width: 100%;
    max-width: 100%;
    height: auto;
}

.visual-placeholder {
    color: var(--text-muted);
    font-size: 0.9rem;
    text-align: center;
}

.visual-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 0.75rem;
    margin-top: 0.5rem;
    font-size: 0.7rem;
    color: var(--text-secondary);
}

/* Live Layer Breakdown (Phase A — populated from registry) */
.visual-legend .layer-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    width: 100%;
}
.visual-legend .layer-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 8px 3px 5px;
    background: #161b22;
    border: 1px solid #2a2f38;
    border-radius: 999px;
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.3px;
    transition: transform 0.15s ease, border-color 0.15s ease;
    cursor: default;
}
.visual-legend .layer-pill:hover {
    transform: translateY(-1px);
    border-color: #3a404a;
}
.visual-legend .layer-pill .swatch {
    width: 9px;
    height: 9px;
    border-radius: 2px;
    flex: 0 0 auto;
    box-shadow: 0 0 0 1px rgba(255,255,255,0.15) inset;
}
.visual-legend .layer-pill .name {
    color: var(--text-primary);
    font-weight: 700;
}
.visual-legend .layer-pill .bytes {
    color: var(--color-green);
    font-variant-numeric: tabular-nums;
}
.visual-legend .layer-pill .pct {
    color: var(--text-muted);
    font-size: 0.6rem;
    font-weight: 500;
}

/* Always-visible Quick Add palette (Phase A stepping stone to workbench) */
.quick-add {
    margin-top: 0.75rem;
    padding-top: 0.5rem;
    border-top: 1px solid #1f2329;
}
.quick-add-label {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--color-cyan);
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}
.always-palette {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}
.always-palette .preset-chip {
    font-size: 0.72rem;
    padding: 4px 9px;
    border-radius: 999px;
    background: #161b22;
    border: 1px solid var(--color-green-15);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.1s ease;
    white-space: nowrap;
}
.always-palette .preset-chip:hover {
    background: #1f2329;
    border-color: var(--color-green);
    transform: translateY(-1px);
}
.quick-add-hint {
    margin-top: 4px;
    font-size: 0.6rem;
    color: var(--text-muted);
}

/* ============================================================
   PROTOCOL WORKBENCH — Full split-view presentation (Phase B)
   Desktop: two-column grid (left = wire + inspector, right = palette + stack)
   Mobile: graceful single-column with the right panel flowing below
   ============================================================ */

.workbench {
    display: grid;
    grid-template-columns: 1fr 360px;
    gap: 1.25rem 1.5rem;
    align-items: start;
}

@media (max-width: 1024px) {
    .workbench {
        grid-template-columns: 1fr; /* single column on tablets and below */
    }
    .workbench-right {
        order: 2; /* stack below on narrow */
    }
}

/* Left column (hero wire + legend + contextual inspector) */
.workbench-left {
    min-width: 0; /* allow SVG to shrink gracefully */
}

/* Right column — the builder sidebar */
.workbench-right {
    min-width: 0;
}

.workbench-right .builder-section {
    margin: 0;
    border: 1px solid #2a2f38;
    background: #0d1117;
    border-radius: var(--radius-lg);
    padding: 0.75rem 0.9rem;
}

.workbench-right .section-header h2 {
    font-size: 0.85rem;
    margin-bottom: 0.35rem;
}

.workbench-right .stack-list {
    max-height: 340px;
    overflow-y: auto;
    padding-right: 4px;
}

.workbench-right .stack-hint {
    font-size: 0.62rem;
}

/* Layer color accent bar on stack rows (subtle left indicator) */
.stack-row {
    position: relative;
    padding-left: 10px;
}
.stack-row::before {
    content: "";
    position: absolute;
    left: 0;
    top: 6px;
    bottom: 6px;
    width: 4px;
    background: var(--row-layer-color, #3a404a);
    border-radius: 2px;
    opacity: 0.85;
}

/* Richer sidebar palette (always-visible version of chips) */
.workbench-right .always-palette {
    max-height: 210px;
    overflow-y: auto;
    padding: 4px 2px;
    gap: 5px;
}
.workbench-right .always-palette .preset-chip {
    font-size: 0.68rem;
    padding: 5px 10px;
    border-radius: 999px;
}

/* Make the old quick-add section feel native in the sidebar */
.workbench-right .quick-add {
    margin-top: 0.6rem;
    padding-top: 0.5rem;
    border-top: 1px solid #1f2329;
}
.workbench-right .quick-add-label {
    font-size: 0.6rem;
}

/* On wide screens the metrics can breathe more */
@media (min-width: 1024px) {
    .metrics-bar {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* Small polish for the inspector when inside the left column */
.workbench-left .header-detail-expansion {
    margin-top: 0.75rem;
}

/* Quickstarts row in the sidebar (Phase C polish) */
.quickstarts {
    margin-bottom: 0.75rem;
}
.quickstarts-label {
    font-size: 0.6rem;
    font-weight: 700;
    color: var(--color-cyan);
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}
.quickstarts-row {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}
.quickstarts-row .quickstart-card {
    font-size: 0.62rem;
    padding: 5px 8px;
    background: #161b22;
    border: 1px solid #2a2f38;
    border-radius: 6px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.1s ease;
    white-space: nowrap;
    max-width: 100%;
}
.quickstarts-row .quickstart-card:hover {
    border-color: var(--color-green);
    background: #1f2329;
    transform: translateY(-1px);
}
.quickstarts-row .quickstart-card .name {
    font-weight: 600;
}
.quickstarts-row .quickstart-card .desc {
    display: block;
    font-size: 0.55rem;
    color: var(--text-muted);
    margin-top: 1px;
    line-height: 1.1;
}

.physical-layer rect {
    opacity: 0.85;
}

.field-row {
    display: flex;
    justify-content: space-between;
    padding: 2px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.field-row:last-child {
    border-bottom: none;
}
.field-row span:first-child {
    color: var(--text-secondary);
}

/* Floating Hover Tooltip for byte offsets + bit fields */
.hover-tooltip {
    position: fixed;
    background: #111214;
    border: 1px solid var(--color-green-15);
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 0.78rem;
    max-width: 320px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
    z-index: 9999;
    pointer-events: none;
    color: var(--text-primary);
}
.hover-tooltip .offset {
    font-family: monospace;
    color: var(--color-cyan);
    font-weight: 700;
    margin-bottom: 4px;
}
.hover-tooltip .bit-field {
    font-size: 0.72rem;
    line-height: 1.25;
    color: var(--text-secondary);
}

.hover-tooltip .hover-header {
    font-weight: 700;
    margin: 4px 0 6px;
    color: var(--color-green);
}

.hover-tooltip .field-breakdown {
    font-size: 0.75rem;
}

.hover-tooltip .field-item {
    margin-bottom: 4px;
    padding: 2px 0;
    border-left: none;
    background: transparent;
}

.hover-tooltip .field-title {
    font-size: 0.75rem;
}

.hover-tooltip .field-description {
    font-size: 0.68rem;
}

.hover-tooltip .field-title {
    font-weight: 600;
    color: #ddd;
}

.hover-tooltip .bit-range {
    color: var(--color-cyan);
    font-family: monospace;
    font-size: 0.7rem;
    margin-left: 6px;
}

.hover-tooltip .field-description {
    color: var(--text-secondary);
    font-size: 0.72rem;
    line-height: 1.3;
}

.hover-tooltip .hover-hint {
    margin-top: 6px;
    font-size: 0.68rem;
    color: var(--color-cyan);
    font-style: italic;
}

/* Detail panel improvements */
.detail-meta {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 12px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.field-breakdown {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.field-item {
    background: rgba(255, 255, 255, 0.025);
    border-left: 3px solid var(--color-green);
    padding: 8px 12px;
    border-radius: 5px;
    margin-bottom: 5px;
}

/* More generous spacing when the details are expanded below the main diagram */
.header-detail-expansion .field-item {
    padding: 11px 14px;
    margin-bottom: 7px;
}

.field-title {
    font-weight: 600;
    margin-bottom: 2px;
}

.field-description {
    font-size: 0.8rem;
    color: #ccc;
}

.field-explain {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
    font-style: italic;
}

.detail-footer {
    margin-top: 12px;
    font-size: 0.7rem;
    color: var(--text-muted);
    text-align: center;
}

/* === Expanded Header Detail Panel (below main wire diagram) === */
.header-detail-expansion {
    background: #0f1118;
    border: 1px solid var(--color-green-15);
    border-radius: var(--radius-xl);
    padding: 1.25rem 1.6rem;
    margin-bottom: 1.6rem;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.4);
    /* Make it feel like a deliberate "zoom in" area */
    border-left: 5px solid var(--color-green);
}

.expansion-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #2a2f38;
    gap: 12px;
}

.expansion-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.expansion-label {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--color-cyan);
    letter-spacing: 1px;
    margin-right: 8px;
}

.expansion-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-green);
}

.expansion-close {
    background: none;
    border: 1px solid #2a2f38;
    color: var(--text-secondary);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    transition: all 0.15s ease;
}
.expansion-close:hover {
    border-color: var(--color-red);
    color: var(--color-red);
    background: rgba(255, 71, 87, 0.1);
}

/* Row Width Toggle */
.row-width-toggle {
    display: flex;
    background: #161b22;
    border: 1px solid #2a2f38;
    border-radius: 6px;
    overflow: hidden;
    margin-right: 12px;
}

.toggle-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 0.72rem;
    padding: 4px 10px;
    cursor: pointer;
    transition: all 0.15s ease;
    border-right: 1px solid #2a2f38;
}

.toggle-btn:last-child {
    border-right: none;
}

.toggle-btn:hover {
    background: #1f242c;
    color: var(--text-primary);
}

.toggle-btn.active {
    background: var(--color-green);
    color: #0a0a0f;
    font-weight: 600;
}

.expansion-content {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* === RFC-Style Header Diagram === */
.rfc-diagram-container {
    background: #0f1218;
    border: 1px solid #2a2f38;
    border-radius: 8px;
    padding: 10px 12px;
    margin: 8px 0;
}

.rfc-diagram {
    display: block;
    margin: 0 auto;
}

.rfc-diagram-legend {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 6px;
    font-size: 0.72rem;
    color: var(--text-secondary);
}

.rfc-diagram-legend .rfc-note {
    font-size: 0.68rem;
    color: var(--text-muted);
    font-style: italic;
}

.detail-rfc-section {
    margin: 12px 0;
    padding: 8px 0;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.detail-section-title {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--color-cyan);
    letter-spacing: 0.6px;
    margin-bottom: 8px;
    text-transform: uppercase;
}

/* Make the diagram nicer inside the hover tooltip */
.hover-tooltip .rfc-diagram-container {
    background: transparent;
    border: none;
    padding: 4px 0;
    margin-top: 4px;
}

.hover-tooltip .rfc-diagram-legend {
    font-size: 0.65rem;
}

/* When the RFC diagram is shown in the expanded panel below, make it much more readable */
.header-detail-expansion .rfc-diagram {
    width: 100%;
    max-width: 100%;
    display: block;
}

.header-detail-expansion .rfc-diagram-container {
    padding: 10px 8px;
    background: #0c0e14;
    border-radius: 6px;
}

.header-detail-expansion .rfc-diagram-legend {
    font-size: 0.82rem;
    margin-top: 10px;
    justify-content: space-between;
    color: #c8d0db;
}

.header-detail-expansion .rfc-field-box text {
    font-size: 11px !important;
    font-weight: 700;
}

/* === Builder === */
.builder-section {
    margin-bottom: 1rem;
}

.stack-list {
    background: var(--color-surface);
    border: 1px solid var(--color-green-15);
    border-radius: var(--radius-lg);
    min-height: 120px;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.stack-row {
    display: flex;
    align-items: center;
    background: #161b22;
    border: 1px solid #2a2f38;
    border-radius: 6px;
    padding: 0.35rem 0.55rem;
    gap: 0.55rem;
    cursor: grab;
    user-select: none;
    transition: all 0.15s cubic-bezier(0.23, 1, 0.32, 1);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}
.stack-row:hover {
    border-color: #3a404a;
    background: #1a1f27;
}
.stack-row:active {
    cursor: grabbing;
}
.stack-row.dragging {
    opacity: 0.6;
    transform: scale(0.98);
}

.stack-row .drag-handle {
    color: var(--text-muted);
    font-size: 1.1rem;
    line-height: 1;
    width: 18px;
    text-align: center;
}

.stack-row .header-name {
    flex: 1;
    font-weight: 600;
    font-size: 0.9rem;
}

/* RFC badge (small, subtle, visible in stack rows) — Phase 4 RFC surface */
.rfc-badge {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 5px;
    font-size: 0.65rem;
    font-weight: 700;
    line-height: 1;
    border-radius: 3px;
    background: #2a2f38;
    color: #8a9199;
    border: 1px solid #3a404a;
    vertical-align: middle;
    white-space: nowrap;
}

.stack-row .header-bytes {
    font-variant-numeric: tabular-nums;
    color: var(--color-green);
    min-width: 52px;
    text-align: right;
    font-weight: 700;
}

.stack-row .toggle {
    appearance: none;
    width: 18px;
    height: 18px;
    border: 1px solid var(--color-green);
    border-radius: 3px;
    background: transparent;
    cursor: pointer;
    position: relative;
}
.stack-row .toggle:checked {
    background: var(--color-green);
}
.stack-row .toggle:checked::after {
    content: "✓";
    position: absolute;
    top: -1px;
    left: 2px;
    font-size: 12px;
    color: #0a0a0f;
}

.stack-row .remove {
    color: var(--text-muted);
    background: none;
    border: none;
    font-size: 1rem;
    cursor: pointer;
    padding: 0 4px;
}
.stack-row .remove:hover {
    color: var(--color-red);
}

.stack-row .add-another {
    background: var(--color-green-15);
    border: 1px solid var(--color-green);
    color: var(--color-green);
    font-size: 0.7rem;
    padding: 1px 6px;
    border-radius: 4px;
    cursor: pointer;
    margin-left: 4px;
}
.stack-row .add-another:hover {
    background: var(--color-green);
    color: #0a0a0f;
}

.stack-hint {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.4rem;
}

/* Preset Dropdown */
.preset-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    min-width: 220px;
    background: #161b22;
    border: 1px solid #2a2f38;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    z-index: 100;
    margin-top: 6px;
    padding: 4px 0;
}

.preset-option {
    padding: 8px 14px;
    font-size: 0.85rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.1s ease;
}

.preset-option:hover {
    background: #1f242c;
    color: var(--color-green);
}

.preset-option + .preset-option {
    border-top: 1px solid #2a2f38;
}

/* === Presets === */
.presets-section h3 {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.preset-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.preset-chip {
    background: var(--color-surface);
    border: 1px solid var(--color-green-15);
    color: var(--text-primary);
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.1s ease;
}
.preset-chip:hover {
    border-color: var(--color-green);
    color: var(--color-green);
}

/* === Buttons === */
.btn {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--color-green-15);
    padding: 0.35rem 0.8rem;
    border-radius: 6px;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.1s ease;
}
.btn:hover {
    border-color: var(--color-green);
    color: var(--color-green);
}
.btn-primary {
    border-color: var(--color-green);
}
.btn-danger {
    border-color: var(--color-red);
    color: var(--color-red);
}

/* === Modal === */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal-content {
    background: var(--color-surface);
    border: 1px solid var(--color-green-15);
    border-radius: var(--radius-xl);
    padding: 1.25rem;
    width: 90%;
    max-width: 520px;
}

/* === Toast === */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--color-green);
    color: #0a0a0f;
    padding: 0.6rem 1.2rem;
    border-radius: 6px;
    font-size: 0.85rem;
    opacity: 0;
    pointer-events: none;
    transition: all 0.2s ease;
    z-index: 2000;
}
.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Responsive */
@media (max-width: 640px) {
    .app-container {
        padding: 1rem;
    }
    .metrics-bar {
        grid-template-columns: repeat(2, 1fr);
    }
    .packet-visual {
        min-height: 140px;
        padding: 0.75rem;
    }
}
