/* * Base Reset & THEME VARIABLES */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    scroll-behavior: auto !important;
}

:root {
    --bg-body: #f0f2f5;
    --bg-surface: #ffffff;
    --text-primary: #222222; 
    --text-secondary: #555555; 
    --border-color: #e0e0e0;
    --border-light: #eeeeee;
    --header-bg: #22303e; 
    --header-text: #ffffff;
    --sidebar-bg: #f8f9fa;
    --sidebar-card-bg: #ffffff;
    --sidebar-link: #2c3e50; 
    --sidebar-link-active: #227cbf; 
    --card-shadow: 0 2px 5px rgba(0,0,0,0.08);
    --card-shadow-hover: 0 5px 15px rgba(0,0,0,0.12);
    --primary-btn: #227cbf; 
    --primary-btn-hover: #1a6299; 
    --primary-btn-text: #ffffff;
    --info-bg: #eaf4fc;
    --info-border: #227cbf;
    --info-text: #1a252f;
    --guide-bg: #fdf2e9;
    --guide-border: #c85a17; 
    --density-bg: #eafaf1;
    --density-border: #229954; 
    --table-header-bg: #f8f9fa;
    --table-row-even: #fafbfc;
    --table-hover: #eaf4fc;
    --input-bg: #ffffff;
    --input-border: #888888; 
    --input-text: #222222;
    --modal-overlay: rgba(0, 0, 0, 0.6);
    
    --beta-bg: #c85a17;
    --beta-text: #ffffff;
    --status-pass: #229954;
    --status-fail: #d32f2f;
}

[data-theme="dark"] {
    --bg-body: #0f0f0f;
    --bg-surface: #1a1a1a;
    --text-primary: #ffffff;
    --text-secondary: #d4d4d4; 
    --border-color: #333333; 
    --border-light: #252525;
    --header-bg: #161b22;
    --header-text: #e0e0e0;
    --sidebar-bg: #121212;
    --sidebar-card-bg: #1e1e1e;
    --sidebar-link: #cccccc;
    --sidebar-link-active: #5faee3;
    --card-shadow: 0 4px 10px rgba(0,0,0,0.4);
    --card-shadow-hover: 0 8px 20px rgba(0,0,0,0.6);
    --primary-btn: #227cbf; 
    --primary-btn-hover: #3498db; 
    --primary-btn-text: #ffffff;
    --info-bg: #1e2a35;
    --info-border: #5faee3;
    --info-text: #e0e0e0;
    --guide-bg: #2d1d12;
    --guide-border: #e67e22;
    --density-bg: #142b1e;
    --density-border: #2ecc71; 
    --table-header-bg: #2a3744; 
    --table-row-even: #222222;
    --table-hover: #3d566e;
    --input-bg: #252525;
    --input-border: #777777; 
    --input-text: #ffffff;
    --modal-overlay: rgba(0, 0, 0, 0.8);
    
    --beta-bg: #e67e22;
    --beta-text: #121212;
    --status-pass: #2ecc71;
    --status-fail: #ff6b6b;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* =========================================
 * ACCESSIBILITY: SKIP NAVIGATION LINK
 * ========================================= */
.skip-nav-link {
    position: absolute;
    top: -100px; 
    left: 20px;
    background-color: var(--sidebar-link-active);
    color: #ffffff;
    padding: 10px 20px;
    font-weight: 700;
    border-radius: 0 0 8px 8px;
    z-index: 999999;
    text-decoration: none;
    transition: top 0.3s ease;
}

.skip-nav-link:focus {
    top: 0; 
    outline: 3px solid #ffffff !important;
}

/* =========================================
 * ACCESSIBILITY: FOCUS MANAGEMENT 
 * ========================================= */
*:focus-visible {
    outline: 3px solid var(--sidebar-link-active) !important;
    outline-offset: 3px !important;
    border-radius: 4px; 
}

*:focus:not(:focus-visible) {
    outline: none;
}

h2:focus { outline: none !important; }

/* Layout Components */
.app-header {
    background-color: var(--header-bg);
    color: var(--header-text);
    padding: 0.8rem 2rem;
    position: relative; 
    display: flex;
    align-items: center;
    justify-content: center; 
    min-height: 80px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    z-index: 100;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 1400px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header-titles {
    flex: 1; 
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 0 1rem; 
}

/* Two-tone title effect */
.header-titles h1 {
    font-size: 1.4rem; 
    letter-spacing: 0.5px;
    margin: 0;
    line-height: 1.2;
    font-weight: 400; 
}

.header-titles h1 strong {
    font-weight: 800;
    color: var(--sidebar-link-active); 
}

.header-disclaimer-badge {
    margin-top: 0.4rem;
    padding: 0.2rem 0.6rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--header-text);
    background-color: rgba(255, 255, 255, 0.15); 
    border-radius: 50px;
}

[data-theme="dark"] .header-disclaimer-badge {
    background-color: rgba(0, 0, 0, 0.3); 
    color: var(--text-secondary);
}

.sidebar-toggle-btn, .home-nav-btn {
    background-color: transparent;
    border: none;
    color: var(--header-text);
    padding: 0.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-toggle-btn { font-size: 1.8rem; }
.home-nav-btn { font-size: 1.4rem; }

.sidebar-toggle-btn:hover, .home-nav-btn:hover {
    color: var(--sidebar-link-active);
}

.theme-toggle-btn {
    background-color: transparent;
    border: 1.5px solid var(--header-text);
    color: var(--header-text);
    padding: 0.5rem 1rem;
    border-radius: 30px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.2s ease;
}

.theme-toggle-btn:hover {
    background-color: var(--header-text);
    color: var(--header-bg);
}

.app-container {
    display: flex;
    flex-direction: row;
    max-width: 1400px;
    margin: 0 auto;
    min-height: calc(100vh - 80px);
}

/* CSS for Collapsing Sidebar */
.sidebar {
    width: 0;
    background-color: var(--sidebar-bg);
    border-right: none;
    padding: 0;
    overflow: hidden;
    transition: width 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    flex-shrink: 0;
}

.sidebar.open {
    width: 280px;
    border-right: 1px solid var(--border-color);
}

.sidebar-inner {
    width: 280px;
    padding: 1.5rem 1rem;
}

.sidebar ul { list-style: none; }
.sidebar li { margin-bottom: 1rem; }

.sidebar li.nav-divider {
    height: 2px;
    background-color: var(--border-color);
    margin: 1.5rem 1rem;
    border-radius: 2px;
}

.sidebar a {
    text-decoration: none;
    color: var(--sidebar-link);
    font-weight: 600;
    font-size: 0.95rem;
    display: block;
    padding: 1.2rem 1rem;
    background-color: var(--sidebar-card-bg);
    border-radius: 12px;
    box-shadow: var(--card-shadow);
    border: 1px solid var(--border-color);
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    text-align: left;
}

.sidebar a:hover {
    transform: translateY(-4px);
    box-shadow: var(--card-shadow-hover);
    color: var(--sidebar-link-active);
    border-color: var(--sidebar-link-active);
}

.sidebar a.active {
    background-color: var(--sidebar-link-active);
    color: #ffffff;
    border-color: var(--sidebar-link-active);
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.3);
}

/* BETA Tag Styling */
.beta-badge {
    background-color: var(--beta-bg);
    color: var(--beta-text);
    font-size: 0.7rem;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    margin-left: 8px;
    vertical-align: middle;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

/* Active sidebar link overrides beta text color for visibility */
.sidebar a.active .beta-badge {
    background-color: #ffffff;
    color: var(--sidebar-link-active);
}

.calculator-display {
    flex: 1;
    padding: 2.5rem;
    background-color: var(--bg-surface);
}

/* Center the modules */
.calculator-module {
    max-width: 950px;
    margin: 0 auto;
    width: 100%;
}

/* Feature Cards (Converted to buttons for A11y) */
.feature-card {
    cursor: pointer;
    border: 1px solid var(--border-color);
    box-shadow: var(--card-shadow);
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    background: transparent;
    font-family: inherit;
    font-size: 1rem;
    text-align: left;
    color: var(--text-primary);
    width: 100%;
}

.feature-card:hover, .feature-card:focus-visible { 
    transform: translateY(-5px); 
    border-color: var(--sidebar-link-active); 
}
.feature-card strong { color: var(--sidebar-link-active); font-size: 1.1rem; margin-bottom: 0.5rem; display: flex; align-items: center; }

.feature-card span:not(.card-action):not(.beta-badge) {
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 1rem;
    display: block;
}

.card-action { display: block; margin-top: 1rem; font-weight: bold; color: var(--sidebar-link-active); font-size: 0.8rem; }

/* Forms & Inputs */
.input-grid { 
    display: grid; 
    grid-template-columns: repeat(2, 1fr); 
    gap: 1.25rem 2rem; 
    margin-top: 2rem; 
}

.full-span { grid-column: 1 / -1; }
.input-group { display: flex; flex-direction: column; }
.input-group label { margin-bottom: 0.4rem; font-weight: 600; font-size: 0.95rem; text-align: left; color: var(--text-primary); }

.input-group input, 
.input-group select {
    padding: 0.85rem;
    border: 1px solid var(--input-border);
    border-radius: 8px;
    font-size: 1.05rem;
    background-color: var(--input-bg);
    color: var(--input-text);
    width: 100%;
    font-family: inherit;
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; appearance: textfield; }

/* UI Decoration */
.info-box { background-color: var(--info-bg); border-left: 4px solid var(--info-border); padding: 1.2rem; margin-bottom: 1.5rem; border-radius: 8px; color: var(--text-primary); }
.guide-box { background-color: var(--guide-bg); border-left-color: var(--guide-border); }
.density-guide { border-left-color: var(--density-border); background-color: var(--density-bg); margin: 1.5rem; }

.calculator-module h2 { margin-bottom: 0.5rem; color: var(--text-primary); display: flex; align-items: center; }
.calculator-module p { color: var(--text-secondary); margin-bottom: 1rem; }

/* Status Text Modifiers */
.text-pass { color: var(--status-pass) !important; font-weight: 800; font-size: 1.1rem; }
.text-fail { color: var(--status-fail) !important; font-weight: 800; font-size: 1.1rem; }

/* Buttons */
.calculator-module button[id^="btn-calc-"] {
    display: block;
    margin: 2.5rem auto;
    padding: 1rem 3rem;
    font-size: 1.1rem;
    font-weight: 700;
    border-radius: 50px;
    background-color: var(--primary-btn);
    color: var(--primary-btn-text);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(52, 152, 219, 0.2);
    transition: background-color 0.2s ease, transform 0.1s ease;
}
.calculator-module button[id^="btn-calc-"]:hover { background-color: var(--primary-btn-hover); }

/* TABLES & ROBUST HIGHLIGHTS */
.results-container { border: 1px solid var(--border-color); border-radius: 12px; overflow: hidden; margin-top: 1rem; }
.results-table { width: 100%; border-collapse: collapse; background-color: var(--bg-surface); }
.results-table th { background-color: var(--table-header-bg); padding: 1.2rem 1rem; font-size: 0.9rem; text-transform: uppercase; text-align: left; color: var(--text-primary); border-bottom: 2px solid var(--border-color); }
.results-table td { padding: 1.2rem 1rem; border-bottom: 1px solid var(--border-light); text-align: left; color: var(--text-primary); font-size: 1rem; }
.results-table tbody tr:nth-child(even) { background-color: var(--table-row-even); }
.results-table tbody tr { transition: background-color 0.2s ease; }
.results-table tbody tr:hover { background-color: var(--table-hover); }

/* FORCED HIGHLIGHTS */
#ipc-results-body td:nth-child(3),
#ipc-results-body td:nth-child(4),
#hole-to-pad-results-body td:last-child,
#courtyard-results-body td:last-child {
    font-weight: 700 !important;
    color: var(--sidebar-link-active) !important;
    font-size: 1.1rem !important;
}

/* =========================================
 * COPY BUTTON & RESULT CELL STYLING
 * ========================================= */
.result-action-cell {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.generated-name-text {
    font-weight: 700;
    color: var(--sidebar-link-active);
    font-size: 1.1rem;
}

/* Pure Icon Aesthetic */
.calculator-module .copy-btn {
    background-color: transparent !important;
    border: none !important; 
    box-shadow: none !important; 
    outline: none; 
    margin: 0; 
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.4rem;
    line-height: 0; 
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: transform 0.1s ease, color 0.2s ease;
    opacity: 0.7; 
    width: auto;
}

.calculator-module .copy-btn:hover, .calculator-module .copy-btn:focus-visible {
    background-color: transparent !important;
    box-shadow: none !important;
    color: var(--sidebar-link-active); 
    opacity: 1;
    transform: scale(1.1); 
}

/* =========================================
 * SUBTLE DISCLAIMER FOOTER STYLING
 * ========================================= */
.app-disclaimer-footer {
    margin-top: 4rem;
    padding-top: 1.5rem;
    border-top: 1px dashed var(--border-color);
    color: var(--text-secondary);
    font-size: 0.85rem;
    line-height: 1.5;
    text-align: justify;
    opacity: 0.75;
}

/* MODALS */
.modal-overlay {
    position: fixed !important; top: 0; left: 0; width: 100vw; height: 100vh;
    background-color: var(--modal-overlay); display: none; align-items: center; justify-content: center; z-index: 99999; backdrop-filter: blur(4px);
}
.modal-content { background-color: var(--bg-surface); border-radius: 15px; width: 90%; max-width: 450px; overflow: hidden; box-shadow: 0 10px 30px rgba(0,0,0,0.5); }
.modal-header { background-color: #e74c3c; color: white; padding: 1.2rem; display: flex; justify-content: space-between; align-items: center;}
.modal-close-btn { background: transparent; border: none; color: white; font-size: 1.8rem; cursor: pointer; line-height: 1;}
.modal-body { padding: 2rem 1.5rem; color: var(--text-primary); font-size: 1.1rem; line-height: 1.5;}
#custom-alert-text { margin: 0; padding: 0; font-weight: normal; }
.modal-footer { padding: 1rem; background-color: var(--table-header-bg); text-align: right; border-top: 1px solid var(--border-color);}
.modal-footer button { margin: 0; padding: 0.6rem 1.5rem; border-radius: 8px;}

/* =========================================
 * PURE CSS "LATEX" MATH FRACTIONS
 * ========================================= */
.math-fraction {
    display: inline-flex;
    flex-direction: column;
    align-items: stretch; 
    text-align: center;   
    vertical-align: middle;
    font-family: "Cambria Math", "Times New Roman", serif;
    font-style: italic;
    font-size: 1.15rem;
    margin: 0;
    line-height: 1.2;
}

.math-fraction .numerator {
    border-bottom: 1.5px solid var(--text-primary);
    padding: 0.1rem 0.3rem;
}

.math-fraction .denominator {
    padding: 0.1rem 0.3rem;
}

/* =========================================
 * MOBILE TWEAKS
 * ========================================= */
@media (max-width: 768px) {
    .app-header { flex-direction: column; height: auto; padding: 1.5rem; padding-top: 4.5rem; }
    
    .header-content {
        display: flex;
        flex-direction: column;
        width: 100%;
    }
    
    .theme-toggle-btn { position: absolute; right: 1.5rem; top: 1.2rem; margin-top: 0; transform: none; }
    .header-left { position: absolute; left: 1.5rem; top: 1.2rem; transform: none; }
    
    .app-container { flex-direction: column; }
    
    .sidebar { height: 0; }
    .sidebar.open { height: auto; width: 100%; border-right: none; border-bottom: 1px solid var(--border-color); }
    
    .sidebar-inner { width: 100vw; box-sizing: border-box; }
    .sidebar li.nav-divider { display: none; }
    .input-grid { grid-template-columns: 1fr; }
    .app-disclaimer-footer { margin-top: 2.5rem; }

    .results-table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }
}
