* {
    box-sizing: border-box;
}
:root {
    color-scheme: light dark;

    /* Theme Foundations */
    --bg-body: light-dark(#f9f9f9, #111827);
    --bg-surface: light-dark(#ffffff, #1f2937);
    --bg-head: light-dark(#edf2f7, #374151);
    --text-main: light-dark(#1f2937, #f3f4f6);
    --text-muted: light-dark(#4a5568, #9ca3af);
    --border-color: light-dark(#cccccc, #4b5563);
    --shadow-color: light-dark(rgba(0, 0, 0, 0.05), rgba(0, 0, 0, 0.3));
    --alert-color: #de350b;
    --success-color: #2cb72c;

    /* Buttons */
    --btn-bg: #2563eb;
    --btn-primary: #ffffff;
    --btn-prim-hover: #1d4ed8;
    --btn-prim-active: #1e40af;

    /* Toned-down Link Palettes */
    --link-new: light-dark(#2563eb, #60a5fa);
    --link-hover: light-dark(#1d4ed8, #93c5fd);
    --link-visited: light-dark(#7c3aed, #a78bfa);
    --link-underline: light-dark(
        rgba(37, 99, 235, 0.15),
        rgba(96, 165, 250, 0.25)
    );
    --link-visited-underline: light-dark(
        rgba(124, 58, 237, 0.15),
        rgba(167, 139, 250, 0.25)
    );
}

body {
    font-family: sans-serif;
    font-size: 10pt;
    margin: 30px;
    background-color: var(--bg-body);
    color: var(--text-main);
    transition:
        background-color 0.3s ease,
        color 0.3s ease;
    & > header {
        display: flex;
        h2 {
            flex: 1;
        }
    }
}

.query {
    ul {
        color: var(--text-muted);
    }
}

a {
    text-decoration: none;
    transition:
        color 0.15s ease-in-out,
        border-color 0.15s ease-in-out;
    &:link {
        color: var(--link-new);
        border-bottom: 1px solid var(--link-underline);
    }

    &:hover,
    &:active {
        color: var(--link-hover);
        border-bottom-color: var(--link-hover);
    }

    &:visited {
        color: var(--link-visited);
        border-bottom-color: var(--link-visited-underline);
    }
}

table.results {
    width: 100%;
    max-height: 100%;
    overflow-y: auto;
    border-collapse: collapse;
    margin-top: 20px;
    background: var(--bg-surface);
    tr {
        & > :nth-child(3) {
            text-align: right;
            font-variant-numeric: tabular-nums;
        }
        & > :nth-child(1),
        & > :nth-child(6),
        & > :nth-child(8) {
            text-align: center;
        }
    }
    th,
    td {
        padding: 0.6em;
        border: 1px solid var(--border-color);
        text-align: left;
    }
    td.overflow {
        border: 0;
    }
    td.result-actions {
        padding: 0.3em;
        button.edit-btn {
            background: inherit;
            border: 0;
            margin: 0;
            border-radius: 5px;
            padding: 0.5em;
            &:hover {
                background-color: var(--btn-prim-hover);
            }
        }
    }
    thead th {
        background-color: var(--bg-head);
        position: sticky;
        top: 0;
        z-index: 1;
        button {
            background: none;
            padding: 0;
            border: none;
            font: inherit;
            color: inherit;
            cursor: pointer;
            width: 100%;
            text-align: left;
            position: relative;
            text-wrap: nowrap;
            padding-right: 1em;
            &:hover:not(:has(.sort-ord)) {
                &::after {
                    position: absolute;
                    right: 0.3em;
                    content: "▲";
                    color: var(--text-muted);
                }
            }
            .sort-ord {
                position: absolute;
                right: 0.3em;
                top: 50%;
                transform: translateY(-50%);
                align-content: center;
            }
        }
    }
}

input[type="text"] {
    padding: 8px;
    font-size: 14px;
}

button {
    padding: 8px 15px;
    font-size: 14px;
    margin-left: 5px;
    cursor: pointer;
}

input[type="text"],
input[type="number"],
input[type="url"],
input[type="date"],
input[type="password"] {
    padding: 3px 5px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    background-color: var(--bg-body);
    color: var(--text-main);
    transition:
        border-color 0.15s ease,
        box-shadow 0.15s ease;
}

/* Accent highlight colors on interactive selection focus */
input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

/* Style raw file upload tags cleanly */
input[type="file"] {
    color: var(--text-main);
    padding: 5px 0;
}

.sub {
    color: var(--text-muted);
    font-size: 12px;
}

.upload {
    font-size: 0.7rem;
    max-width: min(80vw, 44rem);
    margin-top: 2rem;
    padding: 1em;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 12px var(--shadow-color);
    .title {
        display: flex;
        h3 {
            flex: 1;
            color: var(--text-muted);
            font-size: 1.4rem;
            margin-block: 0.2ex 1ex;
        }
        button {
            border: 0;
            background: inherit;
            font-size: 1.5rem;
            padding: 0;
            color: var(--text-muted);
            &:hover {
                color: var(--btn-prim-hover);
            }
        }
    }
    #upload-feedback {
        font-size: 10pt;
        padding-right: 2em;
        flex: 1;
        text-wrap: balance;
        font-weight: bold;
        place-self: center;
    }
    .notes {
        font-size: 0.8rem;
        color: var(--text-muted);
        b {
            color: var(--alert-color);
        }
        p,
        h5,
        ul {
            margin-block: 0.5rem;
        }
    }
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1ex 1rem;
    .full-width {
        grid-column: span 2;
    }
    .form-error {
        color: var(--alert-color);
    }
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 3px;
    & > * {
        width: 100%;
        display: flex;
    }
    & > span {
        gap: 0.3em;
        input {
            width: 100%;
        }
        button {
            margin: 0;
            padding: 0.2em 0.4em;
            &.btn-delete {
                border: 0;
                background: inherit;
                color: var(--alert-color);
            }
        }
    }
    label {
        font-weight: 600;
        color: var(--text-muted);
    }

    label.required::after {
        content: " *";
        color: var(--alert-color);
    }
    .show-upload {
        border: 0;
        padding: 8px 0;
        cursor: default;
        box-shadow: none;
    }
}

.form-actions {
    padding-top: 20px;
    display: flex;
    justify-content: flex-end;
}

/* Fallback to single column for small mobile viewports */
@media (max-width: 600px) {
    .form-grid {
        grid-template-columns: 1fr;
        .full-width {
            grid-column: span 1;
        }
    }
}

.btn-primary {
    background-color: var(--btn-bg);
    color: var(--btn-primary);
    padding: 0.5rem 1rem;
    font-size: 0.95rem;
    font-weight: 600;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.1s ease;
}

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

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

.alert {
    color: var(--alert-color);
    position: relative;
    padding-left: 1.5em;
    &::before {
        content: "⚠";
        position: absolute;
        left: 0;
        top: 50%;
        transform: translateY(-50%);
        font-size: 140%;
    }
}
.success {
    color: var(--success-color);
}
