/* Color variables */
:root {
    --color-primary: #7350c2;
    --color-primary-dark: #843cff;
    --color-focus-border: rgba(139, 92, 246, 0.2);
    --color-text: #1d1d1f;
    --color-text-disable: #c1c1c1;
    --color-border: #d1d1d6;
    --color-background: #ffffff;
    --color-background-secondary: #f5f5f5;
    --color-table-stripe: #fafafa;
    --color-error: #ff3b30;
    --color-white: #fff;
    --color-shadow: rgba(0, 0, 0, 0.1);
    --color-success-background: #5c14ff;
}

  @media (prefers-color-scheme: dark) {
    :root {
      /* Dark mode */
      --color-primary: #b592ff;
      --color-primary-dark: #7342ff;
      --color-focus-border: rgb(203, 180, 255);
      --color-text: #e5e5e7;
      --color-text-disable: #666666;    
      --color-background: #434343;
      --color-background-secondary: #242426; 
      --color-table-stripe: #2a2a2c; 
      --color-error: #ff453a;
      --color-success-background: #8560f0;
    }
  }

/* Global styles and CSS reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: var(--color-text);
    background-color: var(--color-background-secondary);
    padding: 20px;
    max-width: 1200px;
    margin: 0 auto;
}

/* Header styles */
h1 {
    color: var(--color-text);
    text-align: center;
    margin: 2rem 0;
    font-size: 2.5rem;
    font-weight: 600;
}

/* Form container styles */
#formContainer {
    background-color: var(--color-background);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 4px 6px var(--color-shadow);
    margin: 0 auto 5rem auto;
    max-width: 800px;
}

/* Form element styles */
form {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Label styles */
label, legend {
    display: block;
    font-weight: 500;
    font-size: large;
    color: var(--color-text);
}

.required::after {
    content: " *";
    color: var(--color-error);
    font-weight: bold;
}

/* Input styles */
input[type="text"]:not(#message),
select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.2s ease;
}

input[type="text"]:focus,
select:focus {
    outline: none;
    box-shadow: 0 0 0 2px var(--color-focus-border);
}

/* Checkbox group styles */
fieldset {
    border: 1px solid var(--color-border);
    padding: 1rem;
    border-radius: 8px;
    margin: 2rem 0;
}

fieldset:focus-within {
    box-shadow: 0 0 0 2px var(--color-focus-border);
}

legend {
    padding: 0 0.5rem;
}

/* Checkbox container styles */
fieldset > div {
    display: flex;
    align-items: center;
    margin: 0.5rem 0 0.5rem 1.5rem;
}

fieldset > div > label {
    font-weight: normal;
    margin-inline: 0.5rem;
}

/* Checkbox styles */
input[type="checkbox"] {
    margin-right: 0.5rem;
    cursor: pointer;
    transform: scale(1.2);
    vertical-align: -2px;
    accent-color: var(--color-primary);
}

/* Disabled state styles */
input[type="checkbox"]:disabled,
input[type="radio"]:disabled,
button[type="submit"]:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

input[type="checkbox"]:disabled + label,
input[type="radio"]:disabled + label {
    color: var(--color-text-disable);
    cursor: not-allowed;
}

/* Table styles */
table {
    width: 100%;
    margin: 1rem 0;
    background-color: var(--color-background-secondary);
    border-radius: 8px;
}

th, td {
    padding: 0.75rem;
    text-align: center;
}

th {
    background-color: var(--color-background-secondary);
    font-weight: 600;
}

tr:nth-child(even) {
    background-color: var(--color-table-stripe);
}

/* Radio button styles */
input[type="radio"] {
    cursor: pointer;
    accent-color: var(--color-primary);
}

/* Budget display */
#remainingBudget {
    font-weight: 600;
    color: var(--color-primary);
    text-align: right;
}

/* Submit button styles */
button[type="submit"] {
    background-color: var(--color-primary);
    color: var(--color-white);
    padding: 1rem 2rem;
    border: none;
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.5s ease;
    margin-top: 1rem;
    width: 100%;
}

button[type="submit"]:hover {
    background-color: var(--color-primary-dark);
}

button[type="submit"]:active {
    transform: translateY(1px);
}

/* Error styles */
.error-message {
    color: var(--color-error);
    margin-top: 0.5rem;
    font-size: 0.9rem;
    display: none;
}

.error-list {
    color: var(--color-error);
    margin: 0;
    padding: 0;
    border: 1px solid var(--color-error);
    border-radius: 8px;
    background-color: #fff5f5;
    opacity: 0;
    visibility: hidden;
    max-height: 0;
    transition: opacity 0.3s ease, visibility 0.3s ease, max-height 0.3s ease, margin 0.3s ease, padding 0.3s ease;
    overflow: hidden;
}


.error-list.show {
    margin: 1rem 0;
    padding: 1rem;
    opacity: 1;
    visibility: visible;
    max-height: 500px; 
}

/* Message field styles */
#message {
    width: 100%;
    min-height: 100px;
    padding: 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.2s ease;
    resize: vertical;
    font-family: inherit;
}

#message:focus {
    outline: none;
    box-shadow: 0 0 0 2px var(--color-focus-border);
}

/* Focus styles for accessibility */
input[type="checkbox"]:focus,
input[type="radio"]:focus {
    outline: 2px solid var(--color-focus-border);
    outline-offset: 2px;
}

/* Animation for form elements */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#formContainer > * {
    animation: fadeIn 0.3s ease-out forwards;
}

/* Responsive design */
@media (max-width: 768px) {
    body {
        padding: 1rem;
    }

    #formContainer {
        padding: 1rem;
    }

    h1 {
        font-size: 2rem;
    }

    table {
        font-size: 0.9rem;
    }

    th, td {
        padding: 0.5rem;
    }

    fieldset > div.overflow-x-auto {
        width: 83vw;
    }
}

@media (max-width: 835px) {
    #remainingBudget {
        text-align: left;
        margin-left: 1rem;
    }
    fieldset > div.overflow-x-auto {
        /* width: 80vw; */
        margin: 0 0 1rem 1rem;
    }
}

@media (max-width: 642px) {
    fieldset > div.overflow-x-auto {
        width: 80vw;
    }
}

@media (max-width: 554px) {
    fieldset > div.overflow-x-auto {
        width: 77vw;
    }
}

@media (max-width: 500px) {
    fieldset > div.overflow-x-auto {
        width: 75vw;
    }
}

@media (max-width: 468px) {
    fieldset > div.overflow-x-auto {
        width: 73vw;
    }
}


/* Make table scrollable */
#formContainer {
    width: 100%;
}
  
.overflow-x-auto {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}
  
table {
    min-width: 100%; /* Ensures table takes at least full width */
}

/* Optional: Hide scrollbar but keep functionality */
.overflow-x-auto::-webkit-scrollbar {
    display: none;
}

.overflow-x-auto {
    -ms-overflow-style: none;  /* IE and Edge */
    scrollbar-width: none;  /* Firefox */
}




/* Style the select element itself */
select {
    /* Basic styling */
    background-color: #ffffff; /* or any color you want */
    color: #333333; /* Text color */
    padding: 12px;
    border: 1px solid #cccccc;
    border-radius: 8px;
    font-size: 16px;
    width: 100%;
    
    /* Remove default styling */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

/* Style for iOS picker */
select::-webkit-picker-wrapper,
select::-webkit-list-button {
    background-color: #ffffff; /* Background color for the picker */
    color: #333333; /* Text color for options */
}

/* Style for the dropdown arrow */
.select-wrapper {
    position: relative;
    display: inline-block;
    width: 100%;
}

.select-wrapper::after {
    content: '';
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid #333333;
    pointer-events: none;
}

@keyframes successPulse {
    0% {
        transform: scale(1);
        background-color: var(--color-primary);
    }
    50% {
        transform: scale(1.05);
        background-color: var(--color-success-background);
    }
    100% {
        transform: scale(1);
        background-color: var(--color-success-background);
    }
}

.success-animation {
    animation: successPulse 0.5s ease-out forwards;
}