/* Material Design 3 Styles */

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--md-sys-typescale-body-large-font);
    background-color: var(--md-sys-color-background);
    color: var(--md-sys-color-on-background);
    min-height: 100vh;
    display: flex;
    justify-content: center;
}

.md3-surface {
    width: 100%;
    min-height: 100vh;
    background-color: var(--md-sys-color-surface);
}


/* Typography */
.md3-display-large {
    font-family: var(--md-sys-typescale-display-large-font);
    font-size: var(--md-sys-typescale-display-large-size);
    font-weight: var(--md-sys-typescale-display-large-weight);
    color: var(--md-sys-color-on-surface);
    margin-bottom: 8px;
}

.md3-headline-large {
    font-family: var(--md-sys-typescale-headline-large-font);
    font-size: var(--md-sys-typescale-headline-large-size);
    font-weight: var(--md-sys-typescale-headline-large-weight);
    color: var(--md-sys-color-on-surface);
}

.md3-body-large {
    font-family: var(--md-sys-typescale-body-large-font);
    font-size: var(--md-sys-typescale-body-large-size);
    font-weight: var(--md-sys-typescale-body-large-weight);
    color: var(--md-sys-color-on-surface-variant);
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 48px;
    padding-top: 48px;
    position: relative;
    /* For positioning toggle button if needed, though it's absolute to container */
}

/* Theme Toggle Button */
.theme-toggle-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background-color: transparent;
    color: var(--md-sys-color-on-surface-variant);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, color 0.2s;
    z-index: 10;
}

/* GitHub Button */
.github-btn {
    position: absolute;
    top: 16px;
    left: 16px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: transparent;
    color: var(--md-sys-color-on-surface-variant);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, color 0.2s;
    z-index: 10;
    text-decoration: none;
    /* Remove underline for anchor */
}

.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 24px 16px;
    position: relative;
    /* Anchor for absolute toggle button */
}

/* Cards */
.md3-card {
    background-color: var(--md-sys-color-surface);
    border-radius: var(--md-sys-shape-corner-medium);
    padding: 24px;
    margin-bottom: 24px;
    /* Default: Flat (no shadow) */
    box-shadow: var(--md-sys-elevation-0);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border: 1px solid transparent;
    /* Placeholder for potential border */
}

.search-card {
    background-color: var(--md-sys-color-surface-variant);
    border-radius: var(--md-sys-shape-corner-large);
    /* Flat by default */
    box-shadow: var(--md-sys-elevation-0);
}

/* Hover: 3D / Elevated - Only on devices that support hover */
@media (hover: hover) {
    .md3-card:hover {
        transform: translateY(-4px);
        box-shadow: var(--md-sys-elevation-3);
        z-index: 1;
    }

    .md3-input:hover {
        border-color: var(--md-sys-color-on-surface);
    }

    .md3-button--filled:hover:not(:disabled) {
        box-shadow: var(--md-sys-elevation-1);
    }

    .md3-button:hover .md3-ripple {
        opacity: var(--md-sys-state-hover-state-layer-opacity);
    }

    .theme-toggle-btn:hover,
    .github-btn:hover {
        background-color: var(--md-sys-color-surface-variant);
        color: var(--md-sys-color-on-surface);
    }

    .download-link:hover {
        background-color: var(--md-sys-color-secondary);
        color: var(--md-sys-color-on-secondary);
    }
}

/* Simplified MD3 Text Field */
.md3-input-wrapper {
    position: relative;
    margin-bottom: 24px;
}

.md3-input {
    width: 100%;
    height: 56px;
    padding: 0 16px;
    font-family: inherit;
    font-size: 16px;
    color: var(--md-sys-color-on-surface);
    background: transparent;
    border: 1px solid var(--md-sys-color-outline);
    border-radius: 4px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    z-index: 1;
}

.md3-input:focus {
    border-color: var(--md-sys-color-primary);
    border-width: 2px;
    padding: 0 15px;
    /* Adjust for border width increase */
}

/* Floating Label */
.md3-label {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    background-color: var(--md-sys-color-surface-variant);
    /* Mask the border */
    padding: 0 4px;
    color: var(--md-sys-color-on-surface-variant);
    font-size: 16px;
    transition: all 0.2s ease;
    pointer-events: none;
    z-index: 2;
    /* Sit on top of border */
}

/* Floating State */
.md3-input:focus~.md3-label,
.md3-input:not(:placeholder-shown)~.md3-label {
    top: 0;
    font-size: 12px;
    color: var(--md-sys-color-primary);
}

/* Inactive but filled state */
.md3-input:not(:placeholder-shown):not(:focus)~.md3-label {
    color: var(--md-sys-color-on-surface-variant);
}

/* Error State */
.md3-input.error {
    border-color: var(--md-sys-color-error);
}

.md3-input.error:focus {
    border-color: var(--md-sys-color-error);
}

.md3-input.error~.md3-label {
    color: var(--md-sys-color-error);
}

.error-message {
    font-size: 12px;
    color: var(--md-sys-color-error);
    margin-top: 4px;
    margin-left: 16px;
    display: none;
    /* JS toggles this */
}

/* Robust Autofill Override */
.md3-input:-webkit-autofill,
.md3-input:-webkit-autofill:hover,
.md3-input:-webkit-autofill:focus,
.md3-input:-webkit-autofill:active {
    -webkit-box-shadow: 0 0 0 30px var(--md-sys-color-surface-variant) inset !important;
    -webkit-text-fill-color: var(--md-sys-color-on-surface) !important;
    transition: background-color 5000s ease-in-out 0s;
    caret-color: var(--md-sys-color-on-surface);
    /* Ensure cursor is visible */
}


/* Buttons */
.md3-button {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 48px;
    /* Increased to 48px for better touch target */
    padding: 0 24px;
    border-radius: 24px;
    /* Adjusted radius */
    border: none;
    font-family: var(--md-sys-typescale-label-large-font);
    font-size: var(--md-sys-typescale-label-large-size);
    font-weight: var(--md-sys-typescale-label-large-weight);
    cursor: pointer;
    overflow: hidden;
    transition: box-shadow 0.2s ease, background-color 0.2s ease;
    width: 100%;
    /* Full width on mobile */
}

.md3-button--filled {
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
}

.md3-button--filled:disabled {
    background-color: rgba(28, 27, 31, 0.12);
    color: rgba(28, 27, 31, 0.38);
    cursor: not-allowed;
    box-shadow: none;
}

/* Ripple */
.md3-ripple {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: currentColor;
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
}

.md3-button:active .md3-ripple {
    opacity: var(--md-sys-state-pressed-state-layer-opacity);
}

/* Loading */
.loading {
    display: none;
    text-align: center;
    padding: 24px;
}

.md3-circular-progress {
    width: 48px;
    height: 48px;
    border: 4px solid var(--md-sys-color-surface-variant);
    border-top-color: var(--md-sys-color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Results */
.results-section {
    display: none;
    margin-top: 24px;
}

.section-title {
    margin-bottom: 24px;
}

.md3-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.md3-table th {
    text-align: center;
    padding: 12px 16px;
    color: var(--md-sys-color-on-surface-variant);
    font-weight: 500;
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
    white-space: nowrap;
}

.md3-table td {
    text-align: center;
    padding: 12px 16px;
    color: var(--md-sys-color-on-surface);
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
    white-space: nowrap;
}

.md3-table tr:last-child td {
    border-bottom: none;
}

/* Download Link as Button */
.download-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 32px;
    padding: 0 16px;
    border-radius: 16px;
    background-color: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-on-secondary-container);
    text-decoration: none;
    font-size: 12px;
    font-weight: 500;
    transition: background-color 0.2s;
}

.download-error {
    color: var(--md-sys-color-error);
    font-size: 12px;
}

.no-results {
    display: none;
    text-align: center;
    padding: 48px 0;
    color: var(--md-sys-color-on-surface-variant);
}

.md3-icon-large {
    font-size: 48px;
    margin-bottom: 16px;
    color: var(--md-sys-color-outline);
}

.error-message-box {
    background-color: var(--md-sys-color-error-container);
    color: var(--md-sys-color-on-error-container);
    padding: 16px;
    border-radius: var(--md-sys-shape-corner-medium);
    margin-bottom: 24px;
    display: none;
}

/* Animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes scaleIn {
    from {
        transform: scale(0.95);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Apply Animations */
.container {
    animation: fadeInUp var(--md-sys-motion-duration-medium) var(--md-sys-motion-easing-standard);
}

.md3-card {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}


.results-section {
    animation: scaleIn var(--md-sys-motion-duration-medium) var(--md-sys-motion-easing-standard);
}

/* Enhanced Input Focus */
.md3-input:focus {
    border-color: var(--md-sys-color-primary);
    border-width: 2px;
    padding: 0 15px;
    box-shadow: 0 0 0 4px rgba(33, 150, 243, 0.1);
    /* Subtle glow ring */
}

/* Responsive */
@media (min-width: 600px) {
    .md3-button {
        width: auto;
        /* Inline on desktop */
    }
}

@media (max-width: 600px) {
    .container {
        padding: 16px;
    }

    .md3-display-large {
        font-size: 32px;
        /* Much smaller for mobile */
        margin-bottom: 4px;
    }

    .md3-body-large {
        font-size: 14px;
    }

    .header {
        padding-top: 24px;
        margin-bottom: 24px;
    }

    .md3-card {
        padding: 16px;
        /* Reduce padding */
        margin-bottom: 16px;
    }

    .md3-table th,
    .md3-table td {
        padding: 8px 4px;
        /* Tighter table cells */
        font-size: 12px;
    }
}

.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
}

/* Print Styles */
@media print {

    .header,
    .search-card,
    .md3-button,
    .download-link {
        display: none !important;
    }

    .container {
        max-width: 100%;
        padding: 0;
    }

    .md3-surface {
        background-color: white;
    }

    .md3-card {
        box-shadow: none;
        border: none;
        padding: 0;
    }

    .results-section {
        display: block !important;
        margin-top: 0;
    }

    .md3-table th,
    .md3-table td {
        border: 1px solid #ddd;
        padding: 8px;
        color: black;
    }
}