* {
    box-sizing: border-box;
}

/* =============================================
   ACCESSIBILITY FOUNDATION
   ============================================= */

/* Skip link — hidden until focused by keyboard */
.skip-link {
    position: absolute;
    top: -100px;
    left: 16px;
    z-index: 9999;
    padding: 10px 18px;
    background: #2d3696;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    border-radius: 0 0 6px 6px;
    text-decoration: none;
    transition: top 0.15s ease;
}

.skip-link:focus {
    top: 0;
    outline: 3px solid #f59e0b;
    outline-offset: 2px;
}

/* Screen-reader only utility — visually hidden but read aloud */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Visible focus rings on ALL interactive elements */
:focus-visible {
    outline: 3px solid #6366f1;
    outline-offset: 3px;
    border-radius: 4px;
}

/* Respect reduced-motion preference */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode support */
@media (forced-colors: active) {
    .search-btn,
    .submit-btn,
    .back-button {
        border: 2px solid ButtonText;
    }
    .search-item {
        border: 1px solid ButtonText;
    }
}

/* =============================================
   BASE
   ============================================= */

body {
    font-family: Arial, sans-serif;
    background-color: #ffffff;
    margin: 0;
    padding: 15px;
    overflow-x: hidden;
    /* Ensure minimum readable text size */
    font-size: 16px;
    line-height: 1.6;
    color: #222;
}

html {
    overflow-x: hidden;
    /* Smooth scroll for skip-link jump */
    scroll-behavior: smooth;
}

/* =============================================
   HEADER / NAV
   ============================================= */

#navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-left: 15px;
    padding-right: 15px;
    background: #fff;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 1000;
    min-height: 70px;
    overflow: visible;
}

#logo-link {
    text-decoration: none;
    font-weight: 500;
    margin-left: 20px;
    display: flex;
    align-items: center;
    flex-shrink: 0;
    overflow: hidden;
    /* Visible focus ring override for logo */
    border-radius: 4px;
}

#logo {
    height: 130px;
    width: auto;
    max-width: 300px;
    display: block;
    margin-top: -50px;
    margin-left: -50px;
    margin-right: auto;
}

.nav-links {
    display: flex;
    gap: 20px;
    list-style: none;
    margin: 0;
    padding: 0;
    align-items: center;
    flex-shrink: 0;
}

/* Nav links — larger tap target, visible underline on current/hover */
.nav-links a {
    text-decoration: none;
    white-space: nowrap;
    color: #444;
    font-size: 14px;
    padding: 6px 4px;
    display: inline-block;
    /* Underline indicator */
    border-bottom: 2px solid transparent;
    transition: border-color 0.15s, color 0.15s;
}

.nav-links a:hover {
    color: #2d3696;
    border-bottom-color: #6366f1;
}

/* Current page indicator */
.nav-links a[aria-current="page"] {
    color: #2d3696;
    font-weight: 600;
    border-bottom-color: #6366f1;
}

/* Hamburger — hidden on desktop/tablet */
.hamburger {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 44px;   /* minimum 44x44px touch target */
    height: 44px;
    cursor: pointer;
    background: none;
    border: none;
    padding: 8px;
    flex-shrink: 0;
    border-radius: 6px;
}

.hamburger span {
    display: block;
    width: 22px;
    height: 2px;
    background: #333;
    border-radius: 2px;
    transition: transform 0.3s ease, opacity 0.3s ease;
    transform-origin: center;
}

.hamburger.is-open span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}
.hamburger.is-open span:nth-child(2) {
    opacity: 0;
    transform: scaleX(0);
}
.hamburger.is-open span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

/* =============================================
   MAIN CONTENT
   ============================================= */

main {
    padding-top: 20px;
    /* Ensure main is reachable by skip-link */
    outline: none;
}

.container {
    max-width: 900px;
    margin: auto;
    width: 100%;
    box-sizing: border-box;
    padding-left: 16px;
    padding-right: 16px;
}

h1 {
    text-align: center;
    margin-bottom: 10px;
    font-size: 28px;
    line-height: 1.3;
    color: #1a1a2e;
}

/* Subtitle below h1 — helps users understand the tool instantly */
.page-subtitle {
    text-align: center;
    color: #555;
    font-size: 15px;
    margin: 0 auto 24px;
    max-width: 560px;
    line-height: 1.6;
}

/* Section headings inside info/why blocks */
.section-heading {
    font-size: 16px;
    font-weight: 700;
    color: #2c3e50;
    margin: 0 0 10px;
}

/* =============================================
   SEARCH FORM
   ============================================= */

.form-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    padding: 2rem;
}

.search-form {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    gap: 12px;
}

.form-div {
    width: 100%;
    display: flex;
    justify-content: center;
}

/* Input group — label sits above input */
.input-group {
    flex-direction: column;
    align-items: flex-start;
    max-width: 500px;
    gap: 4px;
}

/* Visible label — improves accessibility vs. placeholder-only */
.input-label {
    font-size: 14px;
    font-weight: 600;
    color: #333;
    display: block;
}

/* Hint text below input */
.input-hint {
    font-size: 12px;
    color: #666;
    margin-top: 4px;
    display: block;
}

/* Search input */
#form-container input,
#keywordInput {
    width: 100%;
    max-width: 500px;
    padding: 11px 14px;
    font-size: 16px;
    border: 1.5px solid #ccc;
    border-radius: 6px;
    transition: border-color 0.2s, box-shadow 0.2s;
    color: #222;
    background: #fff;
}

#form-container input:focus,
#keywordInput:focus {
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
    outline: none;
}

/* Placeholder colour — must meet 3:1 contrast on white */
#keywordInput::placeholder {
    color: #767676;
}

/* =============================================
   TRENDING CHIPS
   ============================================= */

.search-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    width: 100%;
}

.trending {
    color: #ef4444;
    font-size: 14px;
}

.search-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: #f1f5f9;
    border-radius: 20px;
    text-decoration: none;
    color: #222;
    font-size: 13px;
    transition: background 0.2s, color 0.2s;
    /* Minimum 44px touch height */
    min-height: 36px;
    border: 1px solid transparent;
}

.search-item:hover {
    background: #3b82f6;
    color: #fff;
}

.search-item:focus-visible {
    outline: 3px solid #6366f1;
    outline-offset: 2px;
    border-radius: 20px;
}

.search-item .item-trend-icon {
    display: inline-flex;
    align-items: center;
    color: #888;
    flex-shrink: 0;
}

.search-item:hover .item-trend-icon {
    color: #fff;
}

.trending-label {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    font-size: 13px;
    color: #555;
    font-weight: 500;
    margin-bottom: 2px;
}

.trending-label .trending-arrow {
    display: inline-flex;
    align-items: center;
    color: #888;
}

@media (max-width: 600px) {
    .search-item {
        font-size: 12px;
        padding: 6px 10px;
    }
}

/* =============================================
   SEARCH BUTTON
   ============================================= */

.search-form button,
.search-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px 20px;
    background: linear-gradient(135deg, #6366f1, #3b82f6);
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 15px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    transition: box-shadow 0.2s ease, transform 0.15s ease;
    width: 40%;
    min-width: 160px;
    /* Minimum touch target */
    min-height: 44px;
}

.search-form button:hover,
.search-btn:hover {
    box-shadow: 0 6px 12px rgba(45, 54, 150, 0.4);
}

.search-form button:focus-visible,
.search-btn:focus-visible {
    outline: 3px solid #f59e0b;
    outline-offset: 3px;
}

.search-form button:active,
.search-btn:active {
    transform: scale(0.98);
}

/* =============================================
   DISCLAIMER NOTE
   ============================================= */

.disclaimer-note {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    font-size: 12px;
    color: #666;
    margin-top: 6px;
    text-align: left;
    max-width: 500px;
    line-height: 1.5;
}

.disclaimer-icon {
    flex-shrink: 0;
    margin-top: 1px;
    color: #888;
}

/* =============================================
   RESULTS CONTAINER
   ============================================= */

#resultsContainer {
    margin-top: 20px;
    /* Ensure it's reachable when focused by JS */
    outline: none;
}

.software-list {
    display: grid;
    gap: 10px;
    margin: 20px 0;
    list-style: none;
    padding: 10px;
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid #ddd;
    border-radius: 5px;
    background-color: #ffffff;
}

.software-item {
    background-color: #f5f5f5;
    border: 1px solid #ddd;
    padding: 15px;
    margin-bottom: 10px;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.software-item:hover {
    background-color: #e8e8e8;
}

.software-item a {
    text-decoration: none;
    color: #333;
    display: block;
    font-weight: 500;
}

.software-item a:hover {
    color: #007bff;
}

.no-results {
    color: #666;
    text-align: center;
    padding: 20px;
}

/* =============================================
   TABLE (results)
   ============================================= */

/* Scrollable wrapper for narrow screens */
.table-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 4px;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    table-layout: fixed;
}

th, td {
    padding: 12px 15px;
    border: 1px solid #ddd;
    text-align: left;
    font-size: 14px;
    /* Allow long words to wrap */
    word-break: break-word;
}

th {
    background-color: #2c3e50;
    color: white;
    /* Scope is set in HTML — this ensures it looks right */
    font-weight: 600;
}

tr:nth-child(even) {
    background-color: #f9f9f9;
}

tr:hover {
    background-color: #f1f1f1;
}

/* =============================================
   LOADING + ERROR STATES
   ============================================= */

.loading {
    text-align: center;
    color: #666;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    font-size: 16px;
}

.loading-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #2d3696;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-bar {
    width: 100%;
    height: 4px;
    background-color: #e9ecef;
    border-radius: 2px;
    overflow: hidden;
    margin-top: 10px;
}

.loading-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #007bff, #0056b3);
    border-radius: 2px;
    animation: loadingProgress 2s ease-in-out infinite;
}

@keyframes loadingProgress {
    0% { width: 0%; }
    50% { width: 100%; }
    100% { width: 0%; }
}

/* Error state — uses role="alert" in JS, high contrast colours */
.error {
    background-color: #f8d7da;
    color: #5a0e17;
    padding: 12px 16px;
    border-radius: 4px;
    margin-top: 10px;
    border-left: 4px solid #dc3545;
    font-size: 14px;
    line-height: 1.5;
}

/* =============================================
   SOFTWARE SELECTION
   ============================================= */

.software-selection {
    max-width: 100%;
    margin: 20px auto;
    background-color: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.software-selection h2 {
    margin-top: 0;
    color: #2c3e50;
}

.software-selection p {
    color: #666;
    margin-bottom: 20px;
}

.software-item {
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    background-color: #ffffff;
}

.software-item:hover {
    background-color: #f0f0f0;
    border-color: #007bff;
}

.software-item:focus-within {
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.software-item input[type="radio"] {
    cursor: pointer;
    width: 20px;
    height: 20px;
    margin: 0;
    flex-shrink: 0;
    /* Accent colour for the radio button */
    accent-color: #2d3696;
}

.software-item.selected {
    background-color: #e7f3ff;
    border-color: #007bff;
}

.software-item label {
    margin: 0;
    cursor: pointer;
    flex: 1;
    font-size: 15px;
    line-height: 1.4;
}

/* =============================================
   BUTTONS (submit / back)
   ============================================= */

.submit-btn {
    background-color: #2d3696;
    color: white;
    padding: 12px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
    margin-top: 20px;
    width: 100%;
    min-height: 44px;
    transition: background-color 0.2s, box-shadow 0.2s;
    font-weight: bold;
    box-shadow: 0 4px 8px rgba(45, 54, 150, 0.3);
}

.submit-btn:hover:not(:disabled) {
    background-color: #4d5ab6;
    box-shadow: 0 6px 12px rgba(45, 54, 150, 0.4);
}

.submit-btn:focus-visible {
    outline: 3px solid #f59e0b;
    outline-offset: 3px;
}

.submit-btn:disabled {
    background-color: #999;
    cursor: not-allowed;
    box-shadow: none;
}

.back-button {
    padding: 10px 20px;
    background-color: #2d3696;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    min-height: 44px;
    transition: background-color 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 8px rgba(45, 54, 150, 0.2);
}

.back-button:hover {
    background-color: #4d5ab6;
    box-shadow: 0 6px 12px rgba(45, 54, 150, 0.4);
}

.back-button:focus-visible {
    outline: 3px solid #f59e0b;
    outline-offset: 3px;
}

.results-wrapper {
    margin-top: 20px;
}

.back-button-container {
    text-align: center;
    margin-top: 20px;
}

label {
    flex: 1;
    cursor: pointer;
    margin: 0;
}

.cost-note {
    color: #555;
    font-size: 12px;
    margin: 5px 0 0 0;
}

/* =============================================
   FOOTER
   ============================================= */

.site-footer {
    margin-top: 50px;
    padding: 30px;
    background: #f5f5f5;
    font-size: 14px;
    color: #444;
}

.footer-inner {
    max-width: 900px;
    margin: auto;
    text-align: center;
}

.footer-links {
    margin-bottom: 15px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.footer-links a {
    text-decoration: none;
    color: #444;
    padding: 4px 2px;
    /* Underline visible on hover for clarity */
    border-bottom: 1px solid transparent;
    transition: border-color 0.15s, color 0.15s;
}

.footer-links a:hover {
    color: #2d3696;
    border-bottom-color: #2d3696;
}

.footer-disclaimer {
    margin-bottom: 15px;
    line-height: 1.6;
}

.footer-copy {
    font-weight: 500;
}

/* =============================================
   INFO & WHY SECTIONS
   ============================================= */

.info-section {
    background-color: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 30px;
    margin-top: 20px;
    border-left: 4px solid #007bff;
    color: #444;
    line-height: 1.6;
}

.info-section p {
    margin: 8px 0 0;
    font-size: 15px;
}

.info-section.hidden {
    display: none !important;
}

.why-section {
    margin-top: 15px;
    margin-bottom: 30px;
}

.why-section h2,
.why-section h3 {
    color: #2c3e50;
    font-size: 16px;
    margin: 10px 0 12px 0;
}

/* Why list with SVG icons */
.why-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.why-list li {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: 14px;
    color: #444;
    padding: 10px 14px;
    background: #f8f9fa;
    border-radius: 8px;
    line-height: 1.5;
}

.why-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: #e8eaf6;
    border-radius: 50%;
    flex-shrink: 0;
    color: #2d3696;
    margin-top: 1px;
}

/* =============================================
   RESPONSIVE — TABLET (769px – 1024px)
   ============================================= */

@media (max-width: 1024px) and (min-width: 769px) {
    .container {
        max-width: 100%;
        padding-left: 24px;
        padding-right: 24px;
    }

    #logo {
        height: 110px;
        margin-top: -40px;
        margin-left: -30px;
    }

    .search-form {
        max-width: 100%;
    }

    #form-container input,
    #keywordInput {
        max-width: 100%;
    }

    .search-form button,
    .search-btn {
        width: 50%;
    }

    table {
        font-size: 13px;
    }

    th, td {
        padding: 10px 12px;
    }
}

/* =============================================
   RESPONSIVE — MOBILE (≤768px)
   ============================================= */

@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    /* Show hamburger, hide nav links */
    .hamburger {
        display: flex;
    }

    #navbar {
        flex-wrap: wrap;
        padding: 8px 15px;
        min-height: unset;
        gap: 0;
    }

    #logo-link {
        flex: 1;
        margin-left: 0;
    }

    #logo {
        height: 80px;
        margin-top: -20px;
        margin-left: -20px;
    }

    /* Nav links hidden by default — toggled by JS */
    .nav-links {
        display: none;
        flex-direction: column;
        width: 100%;
        gap: 0;
        padding: 4px 0 8px;
        border-top: 1px solid #eee;
        margin-top: 8px;
    }

    .nav-links.nav-open {
        display: flex;
    }

    .nav-links li {
        width: 100%;
    }

    .nav-links li a {
        display: block;
        padding: 12px 8px;
        font-size: 15px;
        color: #333;
        border-bottom: 1px solid #f0f0f0;
        border-bottom-color: #f0f0f0;
        /* Override desktop underline style */
        border-bottom-width: 1px;
        border-bottom-style: solid;
    }

    .nav-links li:last-child a {
        border-bottom: none;
    }

    .nav-links a[aria-current="page"] {
        background: #f0f4ff;
        padding-left: 12px;
        border-left: 3px solid #6366f1;
    }

    h1 {
        font-size: 22px;
        margin-bottom: 10px;
    }

    h2 {
        font-size: 18px;
    }

    .page-subtitle {
        font-size: 14px;
    }

    .container {
        max-width: 100%;
        padding-left: 8px;
        padding-right: 8px;
    }

    .search-form {
        max-width: 100%;
        gap: 10px;
    }

    .input-group {
        max-width: 100%;
    }

    #form-container input,
    #keywordInput {
        width: 100%;
        max-width: 100%;
    }

    .search-form button,
    .search-btn {
        width: 100%;
        min-width: unset;
    }

    .software-selection {
        padding: 12px;
        margin: 10px auto;
    }

    .software-item {
        padding: 10px;
        gap: 8px;
    }

    .software-item input[type="radio"] {
        width: 18px;
        height: 18px;
    }

    .software-list {
        max-height: 250px;
        padding: 8px;
    }

    th, td {
        padding: 8px 10px;
        font-size: 12px;
    }

    .submit-btn {
        padding: 12px 15px;
        font-size: 14px;
    }

    .back-button {
        width: 100%;
        padding: 12px 15px;
        font-size: 14px;
    }

    .site-footer {
        padding: 20px 15px;
    }

    .why-list li {
        padding: 8px 10px;
        font-size: 13px;
    }
}

/* =============================================
   RESPONSIVE — SMALL MOBILE (≤480px)
   ============================================= */

@media (max-width: 480px) {
    body {
        padding: 8px;
    }

    h1 {
        font-size: 19px;
        margin-bottom: 8px;
    }

    h2 {
        font-size: 16px;
    }

    .search-form {
        gap: 8px;
    }

    #form-container input,
    #keywordInput {
        padding: 10px 12px;
        font-size: 16px;
    }

    .search-form button,
    .search-btn {
        padding: 10px 15px;
        font-size: 14px;
    }

    .software-selection {
        padding: 10px;
        margin: 10px 0;
    }

    .software-selection h2 {
        margin-top: 5px;
    }

    .software-selection p {
        margin-bottom: 15px;
        font-size: 14px;
    }

    .software-item {
        padding: 8px;
        gap: 8px;
        margin-bottom: 8px;
    }

    .software-item input[type="radio"] {
        width: 16px;
        height: 16px;
    }

    .software-list {
        max-height: 200px;
        padding: 8px;
        margin: 15px 0;
    }

    table {
        font-size: 12px;
    }

    th, td {
        padding: 6px 8px;
        font-size: 11px;
    }

    .submit-btn {
        padding: 10px 12px;
        font-size: 13px;
        margin-top: 15px;
    }

    .back-button {
        padding: 10px 12px;
        font-size: 13px;
    }

    #resultsContainer {
        margin-top: 15px;
    }

    .cost-note {
        font-size: 11px;
    }

    .disclaimer-note {
        font-size: 11px;
    }

    .footer-links {
        gap: 6px;
    }

    .why-icon {
        width: 24px;
        height: 24px;
    }
}
