* {
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
    padding: 20px;
}

.container {
    max-width: 700px;
    margin: 0 auto;
    background-color: white;
    padding: 40px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* OUTER RESPONSIVE CONTAINER (no border) */
.hex-grid-container {
    width: fit-content;
    max-width: 100%;
    display: block;                      /* normal flow so wrapper lines up with page content */
    overflow-x: auto;                    /* allow horizontal scroll on small viewports */
    -webkit-overflow-scrolling: touch;
    margin: 0;
    padding: 0;
}

/* Centered container for shared elements */
.hex-matrix-stack {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    width: fit-content;
    max-width: 100%;
    margin: 0 auto;
}

/* VISIBLE BOX — border and shadow match the table width */
.hex-table-wrapper {
    display: inline-block;               /* shrink-to-fit the inner table + search */
    width: fit-content;
    vertical-align: top;
    margin: 20px 0;
    border: 2px solid #555;              /* border belongs here, not on full-width container */
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    outline: none;
    overflow: hidden;                    /* prevent internal overflow showing outside wrapper */
}

/* Table base styles - using ID for maximum specificity */
#node-hex-grid {
    border-collapse: collapse;
    margin: 0;
    font-family: 'Courier New', monospace;
    width: fit-content;                   /* let the table determine wrapper width */
}

#node-hex-grid td,
#node-hex-grid th {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    text-align: center;
    border: 1px solid #1a1a1a !important;
    font-size: 13px;
    font-weight: 500;
    padding: 0 !important;
    box-sizing: border-box;
    line-height: 40px;
}

#node-hex-grid th {
    background: #1a1a1a !important;
    color: #999 !important;
    font-weight: 600;
}

/* Cell type styles with ID selector */
#node-hex-grid td.hex-free {
    background-color: #0f3d1f !important;
    color: #22c55e !important;
    cursor: pointer;
    padding: 0 !important;
}

#node-hex-grid td.hex-used {
    background-color: #5a4a24 !important;
    color: #b8860b !important;
    cursor: pointer;
}

#node-hex-grid td.hex-reserved {
    background-color: #3a3a3a !important;
    color: #888 !important;
    cursor: pointer;
}

#node-hex-grid td.hex-backbone {
    background-color: #4a4a4a !important;
    color: #aaa !important;
    cursor: pointer;
}

#node-hex-grid td.hex-duplicate {
    background-color: #5c1a1a !important;
    color: #ef4444 !important;
    cursor: pointer;
}

/* Reserved + in-use should be visually black */
#node-hex-grid td.hex-reserved-in-use,
#subgrid-hex-grid td.hex-reserved-in-use {
    background-color: #000 !important;
    color: #f5f5f5 !important;
    cursor: pointer;
}

/* Dim reserved + in-use when inactive (primary + secondary) */
#node-hex-grid td.hex-reserved-in-use.hex-inactive,
#subgrid-hex-grid td.hex-reserved-in-use.hex-inactive {
    background-color: #161616 !important;
    color: #cfcfcf !important;
    opacity: 0.55 !important;
    filter: grayscale(35%) !important;
}

/* Inactive state - dimmed color for nodes not heard in 7+ days */
#node-hex-grid td.hex-inactive {
    opacity: 0.5 !important;
    filter: grayscale(40%) !important;
}

/* Dimmed/highlighted states for search */
#node-hex-grid td.hex-dimmed {
    opacity: 0.2;
    filter: grayscale(50%);
    transition: all 0.3s ease;
}

#node-hex-grid td.hex-highlighted {
    opacity: 1;
    filter: none;
    box-shadow: 0 0 12px rgba(34, 197, 94, 0.6);
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 12px rgba(34, 197, 94, 0.6); }
    50%     { box-shadow: 0 0 20px rgba(34, 197, 94, 0.9); }
}

/* Style clickable spans - all use flex to prevent reflow on hover */
.hex-clickable {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    transition: all 0.1s ease;
    line-height: 1;
}

#node-hex-grid td.hex-free:hover .hex-clickable,
#node-hex-grid td.hex-used:hover .hex-clickable,
#node-hex-grid td.hex-duplicate:hover .hex-clickable,
#node-hex-grid td.hex-reserved:hover .hex-clickable,
#node-hex-grid td.hex-backbone:hover .hex-clickable {
    font-size: 16px;
    font-weight: 700;
}

/* Modal Styling */
.hex-modal {
    display: none;
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    background: transparent;
    backdrop-filter: none;
    animation: none;
    margin: 12px 0 0;
}

/* Card-style content (in-page) */
.hex-modal-card {
    width: 100%;
}

.hex-modal-card #hex-modal-body {
    max-width: none;
    background: linear-gradient(145deg, #2a2a2a, #1e1e1e);
    padding: 16px 20px;
    border: 1px solid #444;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
    max-width: 900px;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.hex-modal-content {
    background: linear-gradient(145deg, #2a2a2a, #1e1e1e);
    margin: 10vh auto;
    padding: 0;
    border: 1px solid #444;
    border-radius: 12px;
    width: 85%;
    max-width: 450px;
    min-height: 100px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    animation: slideDown 0.3s ease;
    position: relative;
}

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

.hex-modal-close {
    color: #aaa;
    position: absolute;
    right: 15px;
    top: 10px;
    font-size: 28px;
    font-weight: bold;
    line-height: 1;
    cursor: pointer;
    transition: color 0.2s ease;
    z-index: 1;
    background: transparent;
    border: none;
    padding: 0;
}

.hex-modal-close:hover,
.hex-modal-close:focus { color: #fff; }

#hex-modal-body { padding: 20px 25px 25px 25px; }

/* Info card / badges / layout */
.hex-info-card { color: #e0e0e0; }

.hex-info-header {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 0;
    flex-wrap: wrap;
}

.hex-id-badge {
    font-family: 'Courier New', monospace;
    font-weight: bold;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 16px;
}

.hex-used-badge {
    background: linear-gradient(135deg, #7a5a34, #5a4a24);
    color: #b8860b;
    border: 2px solid #b8860b;
}

.hex-duplicate-badge {
    background: linear-gradient(135deg, #7a2a2a, #5c1a1a);
    color: #ef4444;
    border: 2px solid #ef4444;
}

.hex-reserved-badge {
    background: linear-gradient(135deg, #4a4a4a, #3a3a3a);
    color: #aaa;
    border: 2px solid #888;
}

.hex-backbone-badge {
    background: linear-gradient(135deg, #5a5a5a, #4a4a4a);
    color: #bbb;
    border: 2px solid #999;
}

.hex-free-badge {
    background: linear-gradient(135deg, #1a5a2f, #0f3d1f);
    color: #22c55e;
    border: 2px solid #22c55e;
}

.hex-state-badge {
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

/* Info text / grid */
.hex-info-title,
.hex-modal .hex-info-title,
h2.hex-info-title {
    font-size: 20px;
    font-weight: 700;
    margin: 6px 0 10px 0 !important;
    padding: 0 !important;
    color: #fff;
}

.hex-info-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    margin-bottom: 15px;
}

.hex-info-item {
    background: rgba(255, 255, 255, 0.05);
    padding: 10px 12px;
    border-radius: 6px;
    border-left: 3px solid #b8860b;
}

.hex-info-label {
    display: block;
    font-size: 11px;
    color: #999;
    margin-bottom: 4px;
    font-weight: 600;
}

.hex-info-value {
    display: block;
    font-size: 13px;
    color: #e0e0e0;
    word-break: break-word;
}

/* Contact button / small variants */
.hex-info-contact { text-align: center; margin-top: 18px; }

.hex-contact-btn {
    display: inline-block;
    padding: 10px 24px;
    background: linear-gradient(135deg, #0f3d1f, #1a5a2f);
    color: #22c55e !important;
    text-decoration: none !important;
    border-radius: 6px;
    font-weight: 600;
    font-size: 14px;
    transition: all 0.3s ease;
    border: 2px solid #22c55e;
    cursor: pointer;
}

.hex-contact-btn:hover {
    background: linear-gradient(135deg, #1a5a2f, #247c3f);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(34, 197, 94, 0.3);
}

.hex-contact-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.hex-contact-btn-small {
    display: inline-block;
    padding: 5px 10px;
    background: #0f3d1f;
    color: #22c55e !important;
    text-decoration: none !important;
    border-radius: 4px;
    font-size: 11px;
    margin-top: 6px;
}

.hex-contact-btn-small:hover { background: #1a5a2f; }

.hex-no-contact { color: #888; font-style: italic; font-size: 13px; }
.hex-no-contact-small { color: #666; font-size: 11px; font-style: italic; }

/* Duplicate warning / entries */
.hex-duplicate-warning {
    background: rgba(239, 68, 68, 0.1);
    border-left: 4px solid #ef4444;
    padding: 10px;
    margin: 12px 0;
    border-radius: 4px;
    color: #ef4444;
    font-size: 13px;
}

.hex-duplicates-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 50vh;
    overflow-y: auto;
}

.hex-duplicate-entry {
    background: rgba(255, 255, 255, 0.03);
    padding: 12px;
    border-radius: 8px;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

/* Misc small parts */
.hex-entry-number {
    font-size: 11px;
    color: #ef4444;
    font-weight: 600;
    padding: 3px 8px;
    background: rgba(239, 68, 68, 0.1);
    border-radius: 4px;
}

.hex-duplicate-name { font-size: 16px; margin: 8px 0; color: #fff; }

/* Keygen specific styles */
.hex-keygen-description {
    line-height: 1.3;
    color: #ccc;
    font-size: 13px;
    margin: 8px 0;
    text-align: center;
}

.hex-keygen-results { display: flex; flex-direction: column; gap: 8px; }

.hex-key-section {
    background: rgba(255, 255, 255, 0.05);
    padding: 8px;
    border-radius: 4px;
    border-left: 3px solid #22c55e;
}

.hex-key-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.copy-btn-inline {
    padding: 3px 8px;
    background: #3a3a3a;
    color: #aaa;
    border: 1px solid #555;
    border-radius: 3px;
    cursor: pointer;
    font-size: 10px;
    transition: all 0.2s ease;
}
.copy-btn-inline:hover { background: #4a4a4a; color: #fff; }

.key-output-compact {
    width: 100%;
    font-family: 'Courier New', monospace;
    font-size: 10px;
    background: rgba(0, 0, 0, 0.3);
    color: #e0e0e0;
    border: 1px solid #444;
    border-radius: 3px;
    padding: 6px;
    margin-top: 6px;
    resize: none;
    box-sizing: border-box;
    line-height: 1.3;
    word-break: break-all;
}

.hex-key-stats-inline {
    text-align: center;
    padding: 8px;
    margin-bottom: 12px;
    background: rgba(34, 197, 94, 0.1);
    border-radius: 4px;
    font-size: 11px;
    color: #22c55e;
    font-family: 'Courier New', monospace;
}

/* Keygen footer / credit */
.hex-keygen-footer {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    text-align: center;
}

.hex-keygen-credit {
    font-size: 10px;
    color: #888;
    font-style: italic;
}
.hex-keygen-credit a { color: #22c55e; text-decoration: none; }
.hex-keygen-credit a:hover { color: #fff; text-decoration: underline; }

#keygen-progress {
    color: #22c55e;
    text-align: center;
    font-family: 'Courier New', monospace;
    font-size: 11px;
    margin: 0;
    padding: 6px;
    background: rgba(34, 197, 94, 0.1);
    border-radius: 4px;
}

/* Download / action buttons */
.hex-keygen-actions {
    display: flex;
    justify-content: center;
    align-items: stretch;
    gap: 10px;
    margin-bottom: 12px;
}
.hex-keygen-actions .hex-contact-btn { flex: 1; margin: 0; }

.hex-download-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 14px;
    background: linear-gradient(135deg, #0f3d1f, #1a5a2f);
    color: #22c55e;
    border: 2px solid #22c55e;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
    height: auto;
}
.hex-download-btn:hover {
    background: linear-gradient(135deg, #1a5a2f, #247c3f);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(34, 197, 94, 0.3);
}

/* Key preview and toggles */
.key-preview {
    font-family: 'Courier New', monospace;
    font-size: 12px;
    background: rgba(0, 0, 0, 0.3);
    color: #e0e0e0;
    border: 1px solid #444;
    border-radius: 3px;
    padding: 8px;
    margin-top: 6px;
    text-align: center;
    letter-spacing: 0.5px;
}

.key-toggle-btn {
    display: block;
    width: 100%;
    margin-top: 6px;
    padding: 4px 8px;
    background: rgba(255, 255, 255, 0.05);
    color: #22c55e;
    border: 1px solid rgba(34, 197, 94, 0.3);
    border-radius: 3px;
    cursor: pointer;
    font-size: 10px;
    transition: all 0.2s ease;
}
.key-toggle-btn:hover { background: rgba(255, 255, 255, 0.1); border-color: #22c55e; }

/* Side-by-side layout for height and power */
.hex-info-row { display: flex; gap: 10px; }
.hex-info-half { flex: 1; }

/* Search box styling — responsive and follows wrapper width */
.hex-search-container {
    margin-bottom: 0;
    width: 100%;
    box-sizing: border-box;
    max-width: 100%;
}

.hex-search-wrapper { position: relative; width: 100%; }

.hex-search-input {
    width: 100%;
    padding: 12px 45px 12px 15px;
    font-size: 14px;
    font-family: 'Courier New', monospace;
    background: linear-gradient(145deg, #2a2a2a, #1e1e1e);
    color: #e0e0e0;
    border: none !important;            /* no internal border */
    border-bottom: none;
    border-radius: 6px 6px 0 0 !important; /* keep rounded top corners to match wrapper */
    outline: none;
    transition: all 0.3s ease;
    background-clip: padding-box;       /* avoid bleed over rounded corners */
    box-shadow: none !important;        /* remove any glow that increases perceived thickness */
    box-sizing: border-box;
}
.hex-search-input:focus {
    border-color: #a8d68c;
    box-shadow: 0 0 15px rgba(168, 214, 140, 0.4);
    background: linear-gradient(145deg, #2d2d2d, #202020);
}
.hex-search-input::placeholder { color: #888; font-style: italic; }

/* If Material theme injects a width-limited search rule, ensure input still fills wrapper */
.md-typeset .hex-search-input {
    width: 100% !important;
}

.hex-search-clear {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    color: #999;
    font-size: 16px;
    cursor: pointer;
    padding: 4px 8px;
    transition: all 0.2s ease;
    line-height: 1;
}
.hex-search-clear:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.05); /* keep subtle inner button border only */
}

.hex-search-results {
    text-align: center;
    padding: 6px 10px;
    font-size: 11px;
    color: #22c55e;
    font-family: 'Courier New', monospace;
    min-height: 20px;
    background: rgba(34, 197, 94, 0.1);
    background-clip: padding-box;
    border-left: none !important;
    border-right: none !important;
}

/* Material theme overrides using ID selector (highest specificity) */
.md-typeset #node-hex-grid td {
    background-color: transparent;
    border-color: #1a1a1a !important;
}

.md-typeset #node-hex-grid td.hex-free {
    background-color: #0f3d1f !important;
    color: #22c55e !important;
}
.md-typeset #node-hex-grid td.hex-used {
    background-color: #5a4a24 !important;
    color: #b8860b !important;
}
.md-typeset #node-hex-grid td.hex-reserved {
    background-color: #3a3a3a !important;
    color: #888 !important;
}
.md-typeset #node-hex-grid td.hex-backbone {
    background-color: #4a4a4a !important;
    color: #aaa !important;
}
.md-typeset #node-hex-grid td.hex-duplicate {
    background-color: #5c1a1a !important;
    color: #ef4444 !important;
}

/* ── Sub-grid modal ─────────────────────────────────────────────────────────── */
.hex-subgrid-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.hex-subgrid-modal-content {
    background: var(--card-bg, #1e1e2e);
    border: 1px solid var(--border-color, #444);
    border-radius: 10px;
    padding: 1rem 1.25rem;
    max-width: 95vw;
    max-height: 90vh;
    overflow: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

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

.hex-subgrid-title {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary, #cdd6f4);
}

.hex-subgrid-close {
    background: none;
    border: none;
    color: var(--text-primary, #cdd6f4);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
}

.hex-subgrid-close:hover {
    background: rgba(255,255,255,0.1);
}

.hex-subgrid-table-wrapper {
    overflow: auto;
}

/* Slightly smaller font for the sub-table to keep it compact */
.hex-table-sub {
    font-size: 0.72rem;
}

.hex-table-sub td,
.hex-table-sub th {
    min-width: 2rem;
    padding: 0.2rem 0.25rem;
}

/* Badge showing node count on primary grid cells */
.hex-count {
    display: inline-block;
    background: rgba(255,255,255,0.15);
    border-radius: 999px;
    font-size: 0.6rem;
    padding: 0 0.3em;
    margin-left: 0.2em;
    vertical-align: middle;
    line-height: 1.4;
}

/* Inline drill-down toolbar */
.hex-grid-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 10px;
    background: #1a1a1a;
    border-top: 1px solid #2a2a2a;
    border-bottom: 1px solid #2a2a2a;
    min-height: 42px; /* keeps toolbar from jumping */
    box-sizing: border-box;
}

.hex-grid-title {
    color: #bbb;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    font-weight: 600;
}

.hex-back-button {
    padding: 6px 10px;
    background: #2a2a2a;
    color: #e0e0e0;
    border: 1px solid #444;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    min-width: 72px; /* reserves consistent left-side space */
}

.hex-back-button.is-hidden {
    visibility: hidden;
    pointer-events: none;
}

/* Make secondary table look like primary table */
#subgrid-hex-grid {
    border-collapse: collapse;
    margin: 0;
    font-family: 'Courier New', monospace;
    width: fit-content;
}
#subgrid-hex-grid td,
#subgrid-hex-grid th {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    text-align: center;
    border: 1px solid #1a1a1a !important;
    font-size: 13px;
    font-weight: 500;
    padding: 0 !important;
    box-sizing: border-box;
    line-height: 40px;
}
#subgrid-hex-grid th {
    background: #1a1a1a !important;
    color: #999 !important;
    font-weight: 600;
}
#subgrid-hex-grid td.hex-free { background-color: #0f3d1f !important; color: #22c55e !important; cursor: pointer; }
#subgrid-hex-grid td.hex-used { background-color: #5a4a24 !important; color: #b8860b !important; cursor: pointer; }
#subgrid-hex-grid td.hex-reserved { background-color: #3a3a3a !important; color: #888 !important; cursor: pointer; }
#subgrid-hex-grid td.hex-duplicate { background-color: #5c1a1a !important; color: #ef4444 !important; cursor: pointer; }
#subgrid-hex-grid td.hex-inactive { opacity: 0.5 !important; filter: grayscale(40%) !important; }

/* Ensure reserved-in-use stays black on subgrid (not yellow) */
#subgrid-hex-grid td.hex-reserved-in-use {
    background-color: #000 !important;
    color: #f5f5f5 !important;
    cursor: pointer;
}

/* Less-black variant for inactive reserved-in-use on subgrid */
#subgrid-hex-grid td.hex-reserved-in-use.hex-inactive {
    background-color: #161616 !important;
    color: #cfcfcf !important;
    opacity: 1 !important;
    filter: none !important;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    #node-hex-grid td,
    #node-hex-grid th {
        width: 32px;
        height: 32px;
        min-width: 32px;
        min-height: 32px;
        max-width: 32px;
        max-height: 32px;
        font-size: 10px;
        padding: 0 !important;
        line-height: 32px;
    }

    #node-hex-grid td.hex-free .hex-clickable {
        font-size: 10px;
    }

    /* Disable hover effects on mobile */
    #node-hex-grid td.hex-free:hover .hex-clickable,
    #node-hex-grid td.hex-used:hover .hex-clickable,
    #node-hex-grid td.hex-duplicate:hover .hex-clickable,
    #node-hex-grid td.hex-reserved:hover .hex-clickable,
    #node-hex-grid td.hex-backbone:hover .hex-clickable {
        font-size: 10px;
        font-weight: 500;
    }

    .hex-search-container {
        width: 100%;
        max-width: 100%;
        overflow-x: auto;
    }

    .hex-search-input {
        font-size: 12px;
        padding: 8px 36px 8px 10px;
    }

    .hex-search-results { font-size: 10px; }

    .hex-modal-content {
        width: 95%;
        max-width: none;
        margin: 5vh auto;
    }

    .hex-id-badge { font-size: 14px; padding: 5px 10px; }
    .hex-info-title { font-size: 18px; margin: 0 0 8px 0 !important; }
    .hex-info-value { font-size: 12px; }
    .hex-duplicate-entry { padding: 10px; }
    .hex-keygen-description { font-size: 12px; }
    .hex-keygen-credit { font-size: 9px; }
    #keygen-progress { font-size: 10px; }
    .key-output-compact { font-size: 9px; padding: 5px; }
    .hex-key-stats-inline { font-size: 10px; }
}
