/* CWE Periodic Table Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #ffffff;
    padding: 0;
    margin: 0;
    overflow-x: hidden; /* Prevent horizontal scroll */
    width: 100%;
    box-sizing: border-box;
}

/* Header */
.header {
    background: linear-gradient(135deg, #007ACC 0%, #005a99 100%);
    color: white;
    padding: 10px;
    text-align: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.header-content {
    max-width: 1000px;
    margin: 0 auto;
}

.jki-branding {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin-bottom: 20px;
}

.jki-branding h1 {
    font-size: 2.2em;
    font-weight: 600;
    margin: 0;
}

.jki-logo-link {
    display: inline-block;
    text-decoration: none;
    transition: transform 0.3s ease;
}

.jki-logo-link:hover {
    transform: scale(1.05);
}

.jki-logo {
    height: 50px;
    width: auto;
    display: block;
}

.jki-logo:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.intro-text {
    max-width: 800px;
    margin: 0 auto;
    font-size: 1em;
    line-height: 1.6;
    opacity: 0.95;
}

.intro-text p {
    margin: 0;
}

.intro-text .mitre-link,
.intro-text .article-link,
.intro-text .security-link {
    color: #FFE135;
    text-decoration: underline;
    font-weight: 700;
    transition: all 0.2s;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.intro-text .mitre-link:hover,
.intro-text .article-link:hover,
.intro-text .security-link:hover {
    color: white;
    text-decoration: underline;
    text-shadow: 0 0 8px rgba(255, 255, 255, 0.8);
    transform: scale(1.02);
}

/* Footer */
.footer {
    background: #333;
    color: white;
    padding: 30px 20px;
    text-align: center;
    margin-top: 40px;
}

.footer-content {
    max-width: 1000px;
    margin: 0 auto;
}

.footer-content p {
    margin: 0 0 15px 0;
    font-size: 1em;
    line-height: 1.5;
}

.footer-link {
    color: #87CEEB;
    text-decoration: none;
    font-weight: 600;
    transition: color 0.2s;
}

.footer-link:hover {
    color: #B0E0E6;
    text-decoration: underline;
}

.footer-branding {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #555;
    font-size: 0.9em;
    opacity: 0.8;
}

/* Main container adjustment */
.periodic-table-container {
    width: 100%;
    max-width: 100vw;
    margin: 10px auto;
    background: white;
    padding: clamp(10px, 2vw, 20px);
    box-sizing: border-box;
    overflow-x: auto; /* Allow horizontal scroll as fallback */
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

/* Family Legend */
.family-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-top: 20px;
    padding: 10px;
    background: #fafafa;
    max-width: 900px;
    margin-left: auto;
    margin-right: auto;
    border-radius: 6px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    padding: 4px 8px;
    transition: background-color 0.2s;
    font-size: 12px;
    border-radius: 4px;
}

.legend-item:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.color-box {
    width: 12px;
    height: 12px;
    border: 1px solid #ccc;
    border-radius: 2px;
}

/* CSS Custom Properties for Family Colors */
:root {
    --color-webserver: #4FC3F7;
    --color-auth: #F0E68C;
    --color-data: #DEB887;
    --color-injection: #90EE90;
    --color-stability: #DDA0DD;
    --color-memory: #9370DB;
    --color-external: #87CEEB;
}

.color-box.webserver-attacks { background-color: var(--color-webserver); }
.color-box.authentication-authorization { background-color: var(--color-auth); }
.color-box.data-protection { background-color: var(--color-data); }
.color-box.command-injection { background-color: var(--color-injection); }
.color-box.execution-stability { background-color: var(--color-stability); }
.color-box.memory-handling { background-color: var(--color-memory); }
.color-box.external-data { background-color: var(--color-external); }

/* Periodic Table Grid */
.periodic-table {
    display: grid;
    grid-template-columns: repeat(11, minmax(0, 1fr));
    grid-template-rows: repeat(5, minmax(0, 1fr));
    gap: clamp(2px, 0.5vw, 8px);
    width: 100%;
    min-width: 550px; /* Minimum width to maintain readability */
    max-width: 950px;
    margin: 0 auto;
    padding: clamp(8px, 1.5vw, 20px);
    background: #f8f9fa;
    border-radius: 8px;
    justify-items: stretch;
    align-items: stretch;
    aspect-ratio: 11/5;
    box-sizing: border-box;
}

/* CWE Element - Unified sizing for both table and list views */
.cwe-element {
    position: relative;
    width: 100%;
    height: 100%;
    /* Use container-based sizing instead of viewport units */
    min-width: clamp(35px, calc(100% - 4px), 85px);
    min-height: clamp(35px, calc(100% - 4px), 85px);
    background: #ffffff;
    border: 2px solid #555;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
    padding: clamp(2px, 0.5%, 6px);
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    box-sizing: border-box;
    border-radius: 4px;
    aspect-ratio: 1;
}

.cwe-element:hover {
    transform: translateY(-2px) scale(1.05);
    border-color: #222;
    z-index: 10;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.cwe-element:not(:hover) {
    transition: all 0.5s ease;
}

.cwe-element.family-glow {
    transition: all 0.3s ease, box-shadow 0.3s ease;
}

.cwe-element.family-glow:hover {
    transition: all 0.2s ease, box-shadow 0.2s ease;
}

.cwe-element.family-glow:not(:hover) {
    transition: all 1s ease, box-shadow 1s ease;
}

/* Family Glow Effects */
/* Family Glow Effects - Using CSS Custom Properties */
.cwe-element.family-glow[data-family="webserver-attacks"] {
    box-shadow: inset 0px 0px 0px 4px rgba(79, 195, 247, 0.9);
}

.cwe-element.family-glow[data-family="authentication-authorization"] {
    box-shadow: inset 0px 0px 0px 4px rgba(240, 230, 140, 0.9);
}

.cwe-element.family-glow[data-family="data-protection"] {
    box-shadow: inset 0px 0px 0px 4px rgba(222, 184, 135, 0.9);
}

.cwe-element.family-glow[data-family="command-injection"] {
    box-shadow: inset 0px 0px 0px 4px rgba(144, 238, 144, 0.9);
}

.cwe-element.family-glow[data-family="execution-stability"] {
    box-shadow: inset 0px 0px 0px 4px rgba(221, 160, 221, 0.9);
}

.cwe-element.family-glow[data-family="memory-handling"] {
    box-shadow: inset 0px 0px 0px 4px rgba(147, 112, 219, 0.9);
}

.cwe-element.family-glow[data-family="external-data"] {
    box-shadow: inset 0px 0px 0px 4px rgba(135, 206, 235, 0.9);
}

/* Element Content - Responsive font sizing */
.cwe-rank {
    position: absolute;
    top: clamp(1px, 0.3vw, 3px);
    left: clamp(1px, 0.4vw, 4px);
    font-size: clamp(4px, 1vw, 11px);
    font-weight: bold;
    color: #666;
    line-height: 1;
}

.cwe-rank-mitre {
    position: absolute;
    top: clamp(1px, 0.3vw, 3px);
    right: clamp(1px, 0.4vw, 4px);
    font-size: clamp(4px, 1vw, 11px);
    font-weight: bold;
    color: #666;
    line-height: 1;
}

.cwe-number {
    font-size: clamp(8px, 2.5vw, 18px);
    font-weight: bold;
    color: #333;
    line-height: 1;
    margin: 0;
    text-align: center;
}

.cwe-title {
    font-size: clamp(4px, 1.2vw, 9px);
    color: #555;
    line-height: 1.1;
    margin-top: clamp(1px, 0.2vw, 3px);
    word-wrap: break-word;
    hyphens: auto;
    text-align: center;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    max-height: clamp(12px, 3vw, 27px);
}

/* Controls */
.controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin-top: 20px;
    padding: 15px;
    flex-wrap: wrap;
}

.radio-group {
    display: flex;
    gap: 2px;
    background: #e9ecef;
    border-radius: 6px;
    padding: 2px;
}

.control-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: #f8f9fa;
    border: 2px solid #ddd;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 12px;
}

.radio-btn {
    border: none;
    border-radius: 4px;
    margin: 0;
}

.control-btn:hover {
    background: #e9ecef;
    border-color: #007ACC;
}

.radio-btn:hover {
    background: #d1ecf1;
}

.control-btn.active {
    background: #007ACC;
    color: white;
    border-color: #007ACC;
}

.control-btn .icon {
    font-size: 14px;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: transparent;
    pointer-events: none;
}

.modal-content {
    background-color: #fff;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    width: 90%;
    max-width: 450px;
    max-height: 80vh;
    overflow-y: auto;
    pointer-events: auto;
    border: 2px solid #ddd;
}

/* Modal pinned state */
.modal-content.pinned {
    border: 3px solid #007ACC;
    box-shadow: 0 8px 32px rgba(0, 122, 204, 0.3);
}

.modal-content.pinned::before {
    content: "📌 Pinned - Click outside to close";
    position: absolute;
    top: -22px;
    left: 0;
    background: #007ACC;
    color: white;
    padding: 3px 6px;
    border-radius: 3px;
    font-size: 9px;
    white-space: nowrap;
}

.close {
    position: absolute;
    right: 12px;
    top: 12px;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    color: #999;
    transition: color 0.2s;
}

.close:hover {
    color: #333;
}

/* Modal Content Styling */
.modal-header {
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
    margin-bottom: 15px;
}

.modal-cwe-number {
    font-size: 20px;
    font-weight: bold;
    color: #007ACC;
    margin-bottom: 4px;
}

.modal-official-title {
    font-size: 15px;
    color: #333;
    margin-bottom: 8px;
    line-height: 1.3;
}

.modal-family {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: bold;
    color: white;
    text-transform: uppercase;
}

.modal-section {
    margin-bottom: 12px;
}

.modal-section h3 {
    font-size: 13px;
    color: #666;
    text-transform: uppercase;
    margin-bottom: 6px;
    border-bottom: 1px solid #eee;
    padding-bottom: 3px;
}

.modal-section p {
    line-height: 1.4;
    color: #333;
    font-size: 13px;
}

.modal-ranks {
    display: flex;
    gap: 15px;
    margin-top: 10px;
}

.rank-item {
    text-align: center;
    padding: 8px;
    background: #f8f9fa;
    border-radius: 6px;
    min-width: 70px;
}

.rank-number {
    font-size: 18px;
    font-weight: bold;
    color: #007ACC;
}

.rank-label {
    font-size: 11px;
    color: #666;
    margin-top: 3px;
}

/* List View */
.list-view {
    width: 100%;
    margin: 0 auto;
    padding: clamp(10px, 2vw, 20px);
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: clamp(6px, 1vw, 12px);
    background: #f8f9fa;
    border-radius: 8px;
    justify-content: center;
    align-items: flex-start;
    align-content: flex-start;
    box-sizing: border-box;
}

/* View visibility classes */
.view-hidden {
    display: none !important;
}

.view-table {
    display: grid !important;
}

.view-list {
    display: flex !important;
}

/* List Element Styling - Use same unified sizing as table elements */
.cwe-element.list-element {
    /* Fixed size for list view for consistency */
    width: clamp(50px, 8vw, 85px);
    height: clamp(50px, 8vw, 85px);
    min-width: clamp(50px, 8vw, 85px);
    min-height: clamp(50px, 8vw, 85px);
    max-width: clamp(50px, 8vw, 85px);
    max-height: clamp(50px, 8vw, 85px);
    flex: 0 0 auto;
}

/* Hidden elements */
.cwe-element.hidden {
    display: none;
}

/* Greyed out elements for filtering */
.cwe-element.greyed-out {
    opacity: 0.3;
    filter: grayscale(100%);
    pointer-events: none;
    transform: none !important;
}

.cwe-element.greyed-out:hover {
    transform: none !important;
    border-color: #555 !important;
}

/* Hover highlighting effects */
.cwe-element.highlight-jki {
    border-color: #28a745 !important;
    transform: scale(1.05) !important;
    z-index: 15 !important;
}

.cwe-element.highlight-mitre {
    border-color: #dc3545 !important;
    transform: scale(1.05) !important;
    z-index: 15 !important;
}

.control-btn .icon {
    font-size: 14px;
}

/* Prominent rank styling when filtered */
.cwe-element.show-jki-rank .cwe-rank {
    color: #000 !important;
    font-weight: 900;
    padding: 1px 3px;
}

.cwe-element.show-mitre-rank .cwe-rank-mitre {
    color: #000 !important;
    font-weight: 900;
    padding: 1px 3px;

}

/* Ensure non-prominent ranks are more subdued when filtering */
.cwe-element.show-jki-rank .cwe-rank-mitre {
    opacity: 0.4;
}

.cwe-element.show-mitre-rank .cwe-rank {
    opacity: 0.4;
}

/* Mobile-First Responsive Design */
@media (max-width: 768px) {
    .periodic-table-container {
        margin: 5px;
        padding: 8px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    }
    
    .periodic-table {
        min-width: 480px; /* Ensure minimum readable size */
        gap: 2px;
        padding: 8px;
    }
    
    .cwe-element {
        min-width: 35px;
        min-height: 35px;
        border-width: 1px;
    }
    
    /* Stack controls vertically on mobile */
    .controls {
        flex-direction: column;
        align-items: center;
        gap: 10px;
        padding: 10px;
    }
    
    .radio-group {
        gap: 4px;
    }
    
    .control-btn {
        padding: 6px 12px;
        font-size: 11px;
    }
    
    /* Responsive family legend */
    .family-legend {
        flex-direction: column;
        align-items: center;
        gap: 6px;
        font-size: 11px;
    }
}

@media (max-width: 480px) {
    .periodic-table-container {
        margin: 2px;
        padding: 5px;
    }
    
    .periodic-table {
        min-width: 420px; /* Maintain readability threshold */
        gap: 1px;
        padding: 5px;
    }
    
    .cwe-element {
        min-width: 30px;
        min-height: 30px;
    }
    
    .cwe-number {
        font-size: clamp(6px, 2vw, 12px);
    }
    
    .cwe-title {
        font-size: clamp(3px, 1vw, 7px);
        -webkit-line-clamp: 2;
        line-clamp: 2;
    }
    
    .cwe-rank,
    .cwe-rank-mitre {
        font-size: clamp(3px, 0.8vw, 8px);
    }
}

/* Ultra-small screens - prioritize horizontal scroll */
@media (max-width: 400px) {
    .periodic-table-container {
        padding: 3px;
        border-radius: 4px;
    }
    
    .periodic-table {
        min-width: 220px; /* Absolute minimum for usability */
        border-radius: 4px;
    }
    
   /* Show scroll hint on very small screens */
    /*.periodic-table-container::after {
        content: "← Scroll to explore →";
        display: block;
        text-align: center;
        font-size: 10px;
        color: #666;
        margin-top: 5px;
        font-style: italic;
    }*/
}

/* Desktop optimization */
@media (min-width: 1200px) {
    .periodic-table-container {
        max-width: 1000px;
    }
    
    .periodic-table {
        max-width: 950px;
        gap: 8px;
    }
    
    .cwe-element {
        max-width: 85px;
        max-height: 85px;
    }
}

/* High DPI displays */
@media (min-resolution: 2dppx) {
    .cwe-element {
        border-width: 1.5px;
    }
    
    .cwe-number,
    .cwe-title,
    .cwe-rank,
    .cwe-rank-mitre {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* Print styles */
@media print {
    .periodic-table-container {
        box-shadow: none;
        margin: 0;
        padding: 10px;
    }
    
    .controls,
    .modal {
        display: none !important;
    }
    
    .cwe-element {
        border: 1px solid #333;
        break-inside: avoid;
    }
}

/* Additional Responsive Improvements for Header, Controls, and Modal */

/* Header responsive adjustments */
@media (max-width: 900px) {
    .header {
        padding: 15px 10px;
    }
    
    .jki-branding {
        flex-direction: column;
        gap: 12px;
    }
    
    .jki-branding h1 {
        font-size: 1.8em;
    }
    
    .jki-logo {
        height: 45px;
    }
    
    .intro-text {
        font-size: 0.95em;
    }
    
    .footer {
        padding: 25px 15px;
    }
    
    .modal-content {
        width: 95%;
        margin: 5% auto;
        padding: 12px;
        max-height: 85vh;
    }
}

@media (max-width: 600px) {
    .header {
        padding: 12px 8px;
    }
    
    .jki-branding h1 {
        font-size: 1.5em;
    }
    
    .jki-logo {
        height: 40px;
    }
    
    .intro-text {
        font-size: 0.9em;
    }
    
    /* Improved list view sizing for mobile */
    .cwe-element.list-element {
        width: clamp(45px, 10vw, 60px);
        height: clamp(45px, 10vw, 60px);
        min-width: clamp(45px, 10vw, 60px);
        min-height: clamp(45px, 10vw, 60px);
        max-width: clamp(45px, 10vw, 60px);
        max-height: clamp(45px, 10vw, 60px);
    }
    
    /* Optimize modal for small screens */
    .modal-content {
        width: 98%;
        max-height: 90vh;
        padding: 10px;
        border-radius: 6px;
    }
    
    .modal-header {
        margin-bottom: 10px;
        padding-bottom: 8px;
    }
    
    .modal-cwe-number {
        font-size: 18px;
    }
    
    .modal-official-title {
        font-size: 14px;
    }
}

/* Landscape orientation optimizations for tablets and phones */
@media (max-height: 600px) and (orientation: landscape) {
    .header {
        padding: 8px 10px;
    }
    
    .jki-branding {
        flex-direction: row;
        gap: 15px;
    }
    
    .jki-branding h1 {
        font-size: 1.4em;
    }
    
    .intro-text {
        font-size: 0.85em;
    }
    
    .periodic-table-container {
        margin: 5px auto;
        padding: 8px;
    }
    
    .modal-content {
        max-height: 80vh;
        width: 90%;
    }
}

/* Very wide screens optimization */
@media (min-width: 1400px) {
    .periodic-table-container {
        max-width: 1200px;
    }
    
    .periodic-table {
        max-width: 1100px;
        gap: 10px;
        padding: 25px;
    }
    
    .header-content,
    .footer-content {
        max-width: 1200px;
    }
}
