:root {
    --primary: #00a651;
    --secondary: #008c44;
    --accent: #2ecc71;
    --bg: #1f2122;
    --card-bg: rgba(255, 255, 255, 0.05);
    --text: #ffffff;
    --text-dim: #cccccc;
    --border: rgba(255, 255, 255, 0.1);
    --gradient: linear-gradient(135deg, #00a651 0%, #00d466 100%);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
}

body {
    background-color: var(--bg);
    background-image:
        radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.15) 0, transparent 50%),
        radial-gradient(at 100% 100%, rgba(217, 70, 239, 0.15) 0, transparent 50%);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
    overflow-x: hidden;
    /* Sticky Footer Setup */
    display: flex;
    flex-direction: column;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
    flex: 1;
    /* Pushes footer down */
    width: 100%;
}

/* Header Styles (Restored) */
header {
    text-align: center;
    margin-bottom: 3rem;
    animation: fadeInDown 0.8s ease-out;
}

h1 {
    font-size: 3rem;
    font-weight: 800;
    background: var(--gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.5rem;
}

p.subtitle {
    color: var(--text-dim);
    font-size: 1.1rem;
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

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

/* Layout */
.main-grid {
    display: grid;
    grid-template-columns: 1fr;
    /* Stacked layout like CRD */
    gap: 2rem;
    width: 100%;
    align-items: start;
}

@media (max-width: 1100px) {
    .main-grid {
        grid-template-columns: 1fr;
    }
}

.card {
    background: var(--card-bg);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 2rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

/* Top Parameter Grid (Referenced from crd.html design) */
.main-grid aside.card {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2rem;
    align-items: start;
}

@media (max-width: 992px) {
    .main-grid aside.card {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }
}

/* Form Sections become Grid Items */
.form-section {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
    height: 100%;
}

.form-section-title {
    grid-column: 1 / -1;
    /* Title spans full width */
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
    width: 100%;
}

.parameter-main-title {
    font-size: 1.2rem;
    margin-bottom: 1rem;
}

.checks-config-title {
    font-size: 0.9rem;
    color: var(--primary);
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.form-section:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.form-section h3 {
    font-size: 0.9rem;
    margin-bottom: 1rem;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    /* Subtle separator */
    padding-bottom: 5px;
}

.form-group {
    margin-bottom: 1.2rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    font-size: 0.85rem;
}

input,
select,
textarea {
    width: 100%;
    padding: 0.7rem 0.9rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: white;
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.3s;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
}

option {
    background-color: #333333;
    color: #ffffff;
    padding: 10px;
}

.btn {
    width: 100%;
    padding: 1rem;
    border: none;
    border-radius: 12px;
    background: var(--gradient);
    color: white;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    margin-top: 0.5rem;
}

/* Ensure buttons span full width */
.grid-buttons-3 {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-top: 0.5rem;
}

/* Results Section */
.results-section {
    display: none;
    animation: fadeIn 0.5s ease;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    /* Prevent Grid Blowout */
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

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

.info-card-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

@media (max-width: 768px) {
    .info-card-grid {
        grid-template-columns: 1fr;
    }
}

.summary-box {
    background: rgba(255, 255, 255, 0.05);
    padding: 1.5rem;
    border-radius: 16px;
    border-bottom: 3px solid var(--secondary);
    text-align: center;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--primary);
}

/* Tabs (Added from crd.html ref) */
.tabs {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    background: rgba(255, 255, 255, 0.05);
    padding: 0.5rem;
    border-radius: 15px;
}

.tab {
    flex: 1;
    padding: 0.8rem;
    text-align: center;
    cursor: pointer;
    border-radius: 10px;
    transition: background 0.3s ease;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-dim);
}

.tab.active {
    background: var(--primary);
    color: white;
}

.tab-content {
    display: none;
    animation: fadeIn 0.4s ease;
}

.tab-content.active {
    display: block;
}

/* Table */
.allocation-table-container {
    margin-bottom: 2rem;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
    /* Ensure container itself doesn't scroll wildly, child does */
}

.allocation-header {
    padding: 1rem;
    background: rgba(255, 255, 255, 0.05);
    border-bottom: 1px solid var(--border);
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
}

.allocation-body {
    max-height: 500px;
    overflow-y: auto;
    overflow-x: auto;
    /* Allow horizontal scroll for wide tables */

}

/* Custom Scrollbar for Table Body */
.allocation-body::-webkit-scrollbar {
    height: 8px;
    width: 8px;
}

.allocation-body::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

.allocation-body::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 4px;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}

th {
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-dim);
    position: sticky;
    top: 0;
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);
}

/* Map Visualization */
.location-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    overflow-x: auto;
    padding-bottom: 0.5rem;

}

.location-tabs::-webkit-scrollbar {
    height: 6px;
}

.location-tabs::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
}

.location-tabs::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 3px;
}

.loc-tab {
    padding: 0.6rem 1.2rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    cursor: pointer;
    white-space: nowrap;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-dim);
    border: 1px solid transparent;
    transition: all 0.3s;
}

.loc-tab:hover {
    background: rgba(255, 255, 255, 0.1);
}

.loc-tab.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 12px rgba(0, 166, 81, 0.3);
}

.field-map-view {
    background: #1e293b;
    padding: 2rem;
    border-radius: 20px;
    border: 1px solid var(--border);
}

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

.active-loc-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--secondary);
}

.map-wrapper {
    overflow-x: auto;
    padding-bottom: 1rem;
}

.matrix-grid {
    display: grid;
    gap: 4px;
    margin: 0 auto;
    /* Columns will be set by JS */
}

.cell {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 700;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-dim);
    transition: transform 0.2s;
}

.cell:hover {
    transform: scale(1.1);
    z-index: 2;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}

.cell.check {
    background: var(--accent);
    color: #064e3b;
}

.cell.line {
    background: rgba(99, 102, 241, 0.3);
    border: 1px solid var(--primary);
    color: white;
}

.cell.filler {
    background: rgba(255, 255, 255, 0.02);
    opacity: 0.3;
}

/* Utilities */
.relative-pos {
    position: relative;
}

.d-none {
    display: none !important;
}

.margin-top-1 {
    margin-top: 1rem;
}

.section-header {
    margin-bottom: 1rem;
    color: var(--text-dim);
    font-size: 1.1rem;
}

/* Custom Colors for Buttons */
.btn-generate {
    background: linear-gradient(135deg, #00a651 0%, #00d466 100%);
}

.btn-simulate {
    background: linear-gradient(135deg, #f59e0b 0%, #fbbf24 100%);
    color: #000;
}

.btn-export {
    background: #4b5563;
}

.btn-download-sm {
    width: auto !important;
    padding: 0.5rem 1rem !important;
    font-size: 0.85rem;
}

/* Tooltip */
.tooltip {
    position: relative;
    display: inline-block;
    cursor: help;
    margin-left: 5px;
    color: var(--text-dim);
}

.tooltip .tooltiptext {
    visibility: hidden;
    width: 220px;
    background: #1e293b;
    color: #fff;
    text-align: center;
    border-radius: 8px;
    padding: 10px;
    position: absolute;
    z-index: 20;
    bottom: 125%;
    left: 50%;
    margin-left: -110px;
    opacity: 0;
    font-size: 0.75rem;
    border: 1px solid var(--border);
    transition: opacity 0.3s;
}

.tooltip:hover .tooltiptext {
    visibility: visible;
    opacity: 1;
}

/* Back Button */
.back-btn {
    text-decoration: none;
    color: var(--text);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    transition: all 0.3s;
}

.back-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateX(-3px);
    color: var(--primary);
    border-color: var(--primary);
}

/* Footer Styles */
.main-footer {
    background: rgba(0, 0, 0, 0.3);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--border);
    padding: 2rem 0;
    margin-top: 4rem;
}

.footer-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 2rem;
    flex-wrap: wrap;
}

.footer-left {
    display: flex;
    gap: 1rem;
    flex: 1;
    justify-content: flex-start;
}

.footer-center {
    flex: 1;
    text-align: center;
    color: var(--text-dim);
    font-size: 0.9rem;
    letter-spacing: 0.5px;
}

.footer-right {
    flex: 1;
    display: flex;
    justify-content: flex-end;
    align-items: center;
}

.footer-btn {
    text-decoration: none;
    padding: 0.6rem 1.2rem;
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 600;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
}

.footer-btn i {
    font-size: 1rem;
}

.footer-btn.donate {
    border-color: rgba(231, 76, 60, 0.3);
}

.footer-btn.donate i {
    color: #e74c3c;
}

.footer-btn.donate:hover {
    background: rgba(231, 76, 60, 0.1);
    border-color: #e74c3c;
    transform: translateY(-2px);
}

.footer-btn.query {
    border-color: rgba(52, 152, 219, 0.3);
}

.footer-btn.query i {
    color: #3498db;
}

.footer-btn.query:hover {
    background: rgba(52, 152, 219, 0.1);
    border-color: #3498db;
    transform: translateY(-2px);
}

.developer-info {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(255, 255, 255, 0.03);
    padding: 0.5rem 1rem;
    border-radius: 50px;
    border: 1px solid var(--border);
}

.developer-info span {
    font-size: 0.9rem;
    color: var(--text-dim);
}

.developer-info strong {
    color: var(--text);
    font-weight: 600;
}

.dev-img {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--primary);
    box-shadow: 0 0 10px rgba(0, 166, 81, 0.3);
}

@media (max-width: 992px) {
    .footer-container {
        flex-direction: column;
        text-align: center;
        gap: 1.5rem;
    }

    .footer-left,
    .footer-right {
        justify-content: center;
        flex: none;
    }

    .footer-center {
        order: 3;
    }
}

/* Font Awesome Custom Animation */
.fa-beat-custom {
    --fa-beat-scale: 1.1;
    --fa-animation-duration: 1.5s;
}

/* Donate Tooltip */
.footer-btn.donate {
    position: relative;
    /* Ensure tooltip is positioned relative to button */
}

.donate-tooltip {
    visibility: hidden;
    width: 300px;
    background-color: #1e293b;
    color: #fff;
    text-align: left;
    border-radius: 12px;
    padding: 15px;
    position: absolute;
    z-index: 100;
    bottom: 135%;
    left: 50%;
    transform: translateX(-50%);
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    font-size: 0.85rem;
    line-height: 1.5;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border);
    pointer-events: none;
}

.donate-tooltip::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -8px;
    border-width: 8px;
    border-style: solid;
    border-color: #1e293b transparent transparent transparent;
}

.footer-btn.donate:hover .donate-tooltip {
    visibility: visible;
    opacity: 1;
    transform: translateX(-50%) translateY(-5px);
}

.donate-tooltip strong {
    display: block;
    color: #e74c3c;
    font-size: 0.95rem;
    margin-bottom: 8px;
}

.donate-tooltip p {
    margin-bottom: 8px;
    color: var(--text-dim);
}

.donate-tooltip em {
    display: block;
    margin-top: 10px;
    font-size: 0.75rem;
    color: #94a3b8;
    font-style: italic;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 8px;
}