:root {
    --primary-color: #217346; /* MS Excel/Project Green */
    --primary-hover: #195937; /* Darker green for hover */
    --background: #ffffff;
    --surface: #f8fafc;
    --surface-hover: #f1f5f9;
    --text-primary: #1e293b; /* Dark gray for light mode text */
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --shadow: rgba(0, 0, 0, 0.1);
    --success: #10b981; 
    --warning: #f59e0b;
    --error: #ef4444;
    --project-mode-active: #217346; /* Align with primary green */
}

[data-theme="dark"] {
    --background: #0f172a;
    --surface: #1e293b;
    --surface-hover: #334155;
    --text-primary: #f8fafc; /* Light text for dark mode */
    --text-secondary: #cbd5e1;
    --border: #334155;
    --shadow: rgba(0, 0, 0, 0.3);
    --project-mode-active: #50CB8B; /* Brighter green for dark mode active elements */
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    transition: all 0.3s ease;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem 1rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.header {
    text-align: center;
    margin-bottom: 2rem;
}

.header h1 {
    font-size: clamp(1.8rem, 4vw, 2.5rem);
    font-weight: 700;
    margin-bottom: 0; 
    color: var(--text-primary); 
}

.header p {
    color: var(--text-secondary); 
    font-size: 1.1rem;
    margin-top: 0; 
}

.theme-toggle-link {
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-family: inherit;
    padding: 0;
    font-weight: inherit;
    text-decoration: none;
}

.theme-toggle-link:hover {
    color: var(--text-primary);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.theme-toggle-link span {
    transition: color 0.3s ease;
    display: inline-flex;
    align-items: center;
}

.project-mode-container {
    margin-top: 1.25rem;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    transition: opacity 0.3s ease; 
}

.project-mode-container.disabled {
    opacity: 0.6; 
}

.project-mode-control {
    display: flex;
    align-items: center;
    justify-content: space-between; 
    gap: 1rem;
    font-size: 1rem; 
    color: var(--text-primary); 
    font-weight: 600; 
    margin-bottom: 0.1rem; 
}

.project-mode-toggle-group {
    display: flex;
    gap: 0.5rem; 
    align-items: center;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.25rem;
    background: var(--surface-hover); 
    position: relative;
    top: 3px; 
}

.project-mode-toggle-group span {
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
    color: var(--text-secondary); 
}

.project-mode-toggle-group span.active {
    background: var(--background); 
    color: var(--primary-color); 
    font-weight: 700;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.project-mode-toggle-group span:hover {
    color: var(--primary-color); 
}
.project-mode-toggle-group span.active:hover {
    background: var(--background); 
    color: var(--primary-hover);
}


.calculator-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: 0 4px 6px var(--shadow);
    margin-bottom: 2rem;
}

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

.form-group label {
    display: inline-flex; 
    align-items: center; 
    margin-bottom: 0.5rem; 
    font-weight: 600;
    color: var(--text-primary);
    position: relative; 
    gap: 0.25rem; 
}

.input-row-container {
    display: flex;
    flex-wrap: wrap; 
    gap: 1rem; 
    align-items: flex-end; 
    margin-top: 0.5rem; 
}

input[type="date"] {
    flex: 0 1 180px; 
    padding: 0.75rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: var(--background);
    color: var(--text-primary);
    font-size: 1rem;
    transition: all 0.3s ease;
    font-family: ui-monospace, 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
    font-variant-numeric: tabular-nums slashed-zero;
    font-feature-settings: "zero" 1, "tnum" 1;
    color-scheme: light dark; 
}

input[type="date"]::-webkit-calendar-picker-indicator {
    background-image: url('data:image/svg+xml;charset=UTF-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="%23475569" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="4" width="18" height="18" rx="2" ry="2"></rect><line x1="16" y1="2" x2="16" y2="6"></line><line x1="8" y1="2" x2="8" y2="6"></line><line x1="3" y1="10" x2="21" y2="10"></line></svg>');
    background-size: 16px 16px;
    background-repeat: no-repeat;
    background-position: center;
    width: 20px;
    height: 20px;
    border-radius: 3px;
    cursor: pointer;
    opacity: 0.8;
}

[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator {
    background-image: url('data:image/svg+xml;charset=UTF-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="%23cbd5e1" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="4" width="18" height="18" rx="2" ry="2"></rect><line x1="16" y1="2" x2="16" y2="6"></line><line x1="8" y1="2" x2="8" y2="6"></line><line x1="3" y1="10" x2="21" y2="10"></line></svg>');
}

input[type="date"]::-webkit-calendar-picker-indicator:hover {
    opacity: 1;
}

.duration-expression-input {
    flex: 1; 
    min-width: 180px; 
    padding: 0.75rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: var(--background);
    color: var(--text-primary);
    font-size: 1rem;
    transition: all 0.3s ease;
    font-family: ui-monospace, 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
    font-variant-numeric: tabular-nums slashed-zero;
    font-feature-settings: "zero" 1, "tnum" 1;
}

input[type="date"]:focus, select:focus, input[type="range"]:focus, .duration-expression-input:focus { 
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.info-icon {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 1rem;
    padding: 0;
    vertical-align: middle; 
    flex-shrink: 0; 
    width: 20px; 
    height: 20px; 
    display: inline-flex; 
    align-items: center;
    justify-content: center;
}

.info-icon:hover {
    color: var(--text-primary);
}

.tooltip {
    position: absolute;
    top: calc(100% + 5px); 
    left: 0; 
    z-index: 100;
    background: var(--surface); 
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    box-shadow: 0 4px 12px var(--shadow);
    max-width: 300px; 
    font-size: 0.85rem;
    color: var(--text-primary);
    line-height: 1.4;
    display: none; 
}

.tooltip.show {
    display: block;
}

.tooltip p {
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.tooltip ul {
    list-style: none; 
    padding-left: 0;
    margin: 0;
}

.tooltip li {
    margin-bottom: 0.25rem;
}
.tooltip li:last-child {
    margin-bottom: 0;
}


.schedule-overrun-container {
    margin-top: 1rem; 
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.schedule-overrun-container label {
    font-weight: 600; 
    color: var(--text-primary); 
    font-size: 1rem; 
    margin-bottom: 0; 
}

.schedule-overrun-container .help-text-container {
    padding-left: 0; 
    margin-top: 0.1rem; 
    margin-bottom: 0.5rem; 
}
.schedule-overrun-container .result-note {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-style: italic;
    margin-top: 0; 
}


.slider-control-group {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap; 
}

input[type="range"] {
    -webkit-appearance: none; 
    width: 100%;
    flex: 1; 
    height: 8px; 
    background: var(--border); 
    border-radius: 5px;
    outline: none;
    cursor: pointer;
    transition: background 0.2s ease;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px; 
    height: 20px;
    background: var(--primary-color); 
    border: 2px solid var(--background); 
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2); 
    transition: background 0.15s ease, box-shadow 0.15s ease;
    margin-top: -6px; 
}

input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: var(--primary-color);
    border: 2px solid var(--background);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2);
    transition: background 0.15s ease, box-shadow 0.15s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
    background: var(--primary-hover);
}
input[type="range"]::-moz-range-thumb:hover {
    background: var(--primary-hover);
}

input[type="range"]:focus::-webkit-slider-thumb {
    box-shadow: 0 0 0 3px var(--primary-color), 0 0 0 6px rgba(79, 70, 229, 0.3);
}
input[type="range"]:focus::-moz-range-thumb {
    box-shadow: 0 0 0 3px var(--primary-color), 0 0 0 6px rgba(79, 70, 229, 0.3);
}

.overrun-value-display {
    font-weight: 600;
    min-width: 40px; 
    text-align: right;
}

.overrun-description {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-top: 0.5rem; 
    min-height: 2.5em; 
    line-height: 1.3;
}

.project-mode-note {
    font-size: 0.9rem; 
    color: var(--text-secondary); 
    font-style: italic;
    margin-top: 0; 
    line-height: 1.3; 
    opacity: 1; 
    max-height: 2rem; 
    transition: all 0.3s ease;
    align-self: flex-start; 
}

.button-group {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    margin-top: 1.5rem;
    justify-content: flex-end;
}

.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 120px;
    justify-content: center;
}

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

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--surface-hover);
}

.result-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.result-item {
    align-self: stretch;
}

.copy-link {
    background: none;
    border: 1px solid var(--primary-color);
    color: var(--primary-color);
    padding: 0.375rem 0.75rem;
    border-radius: 4px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    display: block;
    min-width: 80px;
    text-align: center;
}

.copy-link:hover {
    background: var(--primary-color);
    color: white;
}

.copy-link.copied {
    background: var(--success);
    border-color: var(--success);
    color: white;
}

.results {
    background: var(--background);
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    margin-top: 1.5rem;
    min-height: 100px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.results.has-result {
    border-color: var(--success);
    background: linear-gradient(135deg, var(--surface), var(--background));
}

.result-item {
    padding: 1rem;
    background: transparent;
    border-radius: 8px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 1rem;
    line-height: 1.5;
    white-space: normal;
    display: block;
    text-align: left;
}

.result-item:not(.project-mode) {
    gap: 0.5rem;
    padding: 0.75rem 1rem;
}

.result-content {
    width: 100%;
}

.result-content .bold-line {
    font-weight: 600;
    font-size: 1.1rem;
}

.result-note {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-style: italic;
    margin-top: 0.75rem;
    line-height: 1.4;
}

.help-text-container {
    padding-left: 0.75rem;
}

.help-text {
    display: block;
}


.empty-state {
    text-align: center;
    color: var(--text-secondary);
    font-style: italic;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100px;
    flex: 1;
}

.footer {
    margin-top: auto;
    text-align: center;
    padding: 2rem 0;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.footer p {
    margin-bottom: 0.5rem;
}

@media (max-width: 768px) {
    .container {
        padding: 1rem 0.5rem;
    }

    .calculator-card {
        padding: 1.5rem;
    }

    .input-row-container {
        flex-direction: column;
        align-items: stretch; 
    }

    input[type="date"] {
        flex: none; 
        width: 100%; 
    }

    .duration-expression-input {
        flex: none; 
        width: 100%; 
    }

    .button-group {
        flex-direction: column;
    }

    .btn {
        width: 100%;
    }

    .slider-control-group {
        flex-direction: column;
        align-items: stretch;
    }
    .overrun-value-display {
        text-align: left; 
    }

    /* Mobile-specific adjustments for PM Mode toggle */
    .project-mode-toggle-group {
        gap: 0.25rem; /* Reduce gap between ON/OFF buttons */
        padding: 0.2rem 0.4rem; /* Further reduce padding */
        top: 0px; /* Reset top adjustment as it might interfere with flexible sizing */
    }
    .project-mode-toggle-group span {
        padding: 0.2rem 0.4rem; /* Reduce padding to make buttons smaller */
        font-size: 0.8rem; /* Slightly smaller text */
    }

    /* Mobile-specific adjustment for PM Mode Note proximity */
    .project-mode-note {
        margin-top: 0.25rem; /* Add some space back on mobile */
    }
}

@media (max-width: 480px) {
    /* No specific changes needed beyond 768px unless further breakdown is desired */
}

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

/* Focus styles for better accessibility */
.btn:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.theme-toggle-link:focus {
    outline: none;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --border: #000000;
        --shadow: rgba(0, 0, 0, 0.5);
    }
}