/* --- Color Scheme Definitions --- */
:root {
    /* Default: Dark Theme */
    --bg-primary: #2c3e50;
    --bg-secondary: #34495e;
    --bg-tertiary: #606c72;
    --bg-interactive: #4a6572;
    --bg-record: rgba(255, 255, 255, 0.05);
    --bg-overlay: rgba(255, 255, 255, 0.05);
    --text-primary: #ecf0f1;
    --text-secondary: #d1d5db;
    --text-muted: #9ca3af;
    --accent-primary: #3498db;
    --accent-hover: #2980b9;
    --accent-danger: #c0392b;
    --accent-danger-hover: #c82333;
    --border-color: #4a6572;
    --shadow-color: rgba(0, 0, 0, 0.3);
    --action-button: #4a6572;
    --action-button-text: #ecf0f1;
    --action-button-border: none;
    --action-button-hover-bg: #606c72;
    --button-disabled: #2f6181;
    --slider-bg: #3498db;
}

body.theme-light {
    --bg-primary: #f8f9fa;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e9ecef;
    --bg-interactive: #dee2e6;
    --bg-overlay: rgba(0, 0, 0, 0.03);
    --bg-record: #e9ecef;
    --text-primary: #212529;
    --text-secondary: #495057;
    --text-muted: #6c757d;
    --accent-primary: #007bff;
    --accent-hover: #0056b3;
    --accent-danger: #dc3545;
    --accent-danger-hover: #c82333;
    --border-color: #cccfd3;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --action-button: transparent;
    --action-button-text: #007bff;
    --action-button-border: #007bff;
    --action-button-hover-bg: rgba(0, 123, 255, 0.1);
    --button-disabled: #9394a5;
    --slider-bg: #909090;
}

body.theme-og-dark {
    --bg-primary: #212529;
    --bg-secondary: #343a40;
    --bg-tertiary: #454c53;
    --bg-record: #343a40;
    --bg-interactive: hsl(210deg 5.75% 34.12%);
    --bg-overlay: rgba(255, 255, 255, 0.05);
    --text-primary: #e0e1dd;
    --text-secondary: #c2c3c0;
    --text-muted: #a4a5a2;
    --accent-primary: #0d6efd;
    --accent-hover: #4e8dff;
    --accent-danger: #ff5252;
    --accent-danger-hover: #c82333;
    --border-color: rgba(255, 255, 255, 0.15);
    --shadow-color: rgba(0, 0, 0, 0.4);
    --action-button: #0d6efd;
    --action-button-text: #e0e1dd;
    --action-button-border: none;
    --action-button-hover-bg: #0b5ed7;
    --button-hover: #0b5ed7;
    --button-disabled: #2f6181;
    --slider-bg: #0d6efd;
}

/* --- CSS Reset & Base Styles --- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    min-height: 100vh;
}

body {
    font-family: "Inter", sans-serif;
    background-color: var(--bg-primary);
    color: #f3f4f6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    opacity: 1;
    transition: opacity 0.4s ease-in-out;
    overscroll-behavior-y: contain;
    padding-top: env(safe-area-inset-top);
}

/* --- Prevent flash of unstyled content --- */
body.loading {
    opacity: 0;
}

/* --- Prevent scrolling when menu is open --- */
body.menu-open {
    overflow: hidden;
}

.icon {
    display: inline-block;
    width: 24px;
    height: 24px;

    /* This is the key: the background color is our theme color */
    background-color: var(--text-primary);

    /* These properties use an SVG file as a stencil */
    -webkit-mask-size: contain;
    mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
}

/* Now we apply the specific SVG stencil to each icon ID/class */
#refresh-icon {
    -webkit-mask-image: url(./img/refresh-btn.svg);
    mask-image: url(./img/refresh-btn.svg);
}

#menu-icon {
    -webkit-mask-image: url(./img/menu-btn.svg);
    mask-image: url(./img/menu-btn.svg);
}

#close-menu-icon {
    -webkit-mask-image: url(./img/close-btn.svg);
    mask-image: url(./img/close-btn.svg);
}

.back-icon {
    background-color: var(--text-secondary); /* Use a different theme color */
    -webkit-mask-image: url(./img/back-btn.svg);
    mask-image: url(./img/back-btn.svg);
}

.chevron-icon {
    width: 1.5rem; /* Override default size */
    height: 1.5rem;
    background-color: var(--text-muted); /* Use a different theme color */
    -webkit-mask-image: url(./img/small-chevron.svg);
    mask-image: url(./img/small-chevron.svg);
    transition: transform 0.35s ease-out;
}

#logout-icon {
    -webkit-mask-image: url(./img/logout-btn.svg);
    mask-image: url(./img/logout-btn.svg);
}

/* --- App Container --- */
#app {
    max-width: 42rem;
    margin-left: auto;
    margin-right: auto;
}

/* --- Header Styles --- */
#header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
    color: var(--text-primary);
}

#header-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

#logo-img {
    height: 3em;
    width: 3em;
}

#header h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

.header-icon {
    width: 3em;
    height: 3em;
    display: block;
}

#header-buttons {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#header-buttons button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s ease-out;
}

#header-buttons button div {
    width: 24px;
    height: 24px;
    stroke: var(--text-primary);
}

/* --- Main Content --- */
main {
    padding: 1rem;
    position: relative;
}

.view {
    display: none;
    flex-direction: column;
    gap: 1rem;
}

.view.active {
    display: flex;
}

main h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-secondary);
    padding: 0 0.25rem;
}

/* --- Vehicle Card Styles --- */

#vehicle-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    list-style: none;
}

.vehicle-card {
    background-color: var(--bg-overlay);
    border-radius: 0.5rem;
    box-shadow:
        0 4px 6px -1px rgb(0 0 0 / 0.1),
        0 2px 4px -2px rgb(0 0 0 / 0.1);
    color: inherit;
    transition: background-color 200ms ease-in-out;
    overflow: hidden;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    cursor: pointer;
    transition: background-color 0.3s ease-out;
}

.card-header h2 {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text-primary);
}

.card-header p {
    font-size: 0.875rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.chevron-icon {
    width: 1.5rem;
    height: 1.5rem;
    color: var(--text-muted);
    transition: transform 0.12s ease-out;
}

.vehicle-card.expanded .chevron-icon {
    transform: rotate(180deg);
}

.card-details {
    padding: 0 1rem;
    max-height: 0;
    overflow: hidden;
    transition:
        max-height 0.35s ease-out,
        padding 0.35s ease-out;
}

.vehicle-card.expanded .card-details {
    max-height: 10rem; /* A value larger than the content will be */
    padding-bottom: 1rem;
}

.odometer-info {
    padding: 1rem 0;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1rem;
    color: var(--text-secondary);
}

.odometer-info strong {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.action-buttons {
    display: flex;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.action-btn {
    flex-grow: 1;
    border: none;
    border-radius: 0.375rem;
    padding: 0.75rem;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    background-color: var(--action-button);
    border: 1px solid var(--action-button-border);
    color: var(--action-button-text);
    transition: background-color 0.3s ease;
}

/* --- New Record Form Styles --- */

.back-button {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    padding: 0.5rem;
    margin-left: -0.5rem;
    margin-bottom: 0.5rem;
}

.back-button div {
    width: 1.25rem;
    height: 1.25rem;
}

.record-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    background-color: var(--bg-record);
    padding: 1.5rem 1rem;
    border-radius: 0.5rem;
}

.form-btn {
    flex-grow: 1;
    border: none;
    border-radius: 0.375rem;
    padding: 0.875rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease;
    margin-top: 1rem;
}

.save-btn {
    background-color: var(--accent-primary);
    color: #ffffff;
}

.save-btn:disabled {
    background-color: var(--button-disabled);
    color: #c0c0c0;
    cursor: not-allowed;
}

/* --- Form Expander Styles --- */
.form-expander {
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    margin: 0.5rem 0;
}

.form-expander-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 0;
    cursor: pointer;
    font-weight: 500;
    color: var(--text-secondary);
    transition: background-color 0.3s ease-out;
}

.form-details {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.35s ease-out;
}

.record-form.expanded .form-details {
    max-height: 15rem;
}

.record-form.expanded .chevron-icon {
    transform: rotate(180deg);
}

textarea,
input[type="text"] {
    width: 100%;
    padding: 0.75rem;
    background-color: var(--bg-interactive);
    border: 1px solid var(--bg-tertiary);
    border-radius: 0.375rem;
    color: #ffffff;
    font-size: 1rem;
    outline: none;
    transition: box-shadow 150ms ease-in-out;
    font-family: "Inter", sans-serif;
    resize: vertical;
}

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

/* --- Toast History View Styles --- */
#toast-history-list {
    list-style: none;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast-history-item {
    border-left-width: 4px;
    border-style: solid;
    padding: 0.75rem 1rem;
    background-color: var(--bg-secondary);
    border-radius: 0 0.375rem 0.375rem 0;
    box-shadow:
        var(--shadow-color) 0px 1px 3px 0px,
        var(--shadow-color) 0px 1px 2px -1px;
}

.toast-history-item.success {
    border-color: #27ae60;
}

.toast-history-item.error {
    border-color: var(--accent-danger);
}

.toast-history-message {
    color: var(--text-primary);
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.toast-history-timestamp {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* --- Login Modal Styles --- */
#login-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

#login-modal.hidden {
    display: none;
}

#login-modal-content {
    background-color: var(--bg-secondary);
    padding: 2rem;
    border-radius: 0.75rem;
    width: 90%;
    max-width: 24rem;
    box-shadow:
        0 10px 15px -3px rgb(0 0 0 / 0.3),
        0 4px 6px -4px rgb(0 0 0 / 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

#login-modal-content h2 {
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
    color: #ffffff;
    margin-bottom: 1.5rem;
}

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

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

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.form-group input,
textarea {
    width: 100%;
    padding: 0.75rem;
    background-color: var(--bg-interactive);
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    color: var(--text-primary);
    font-size: 1rem;
    outline: none;
    transition: box-shadow 150ms ease-in-out;
}

.form-group input:focus {
    box-shadow: 0 0 0 2px var(--accent-primary);
    border-color: var(--accent-primary);
}

#login-button {
    width: 100%;
    background-color: var(--accent-primary);
    color: #ffffff;
    font-weight: 700;
    padding: 0.75rem 1rem;
    border: none;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: background-color 200ms ease-in-out;
}

/* --- Toggle Switch Styles --- */
.form-group-row {
    display: flex;
    justify-content: space-around;
    gap: 1rem;
    padding: 0.5rem 0;
}

.toggle-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.toggle-group label {
    margin-bottom: 0;
    font-weight: 500;
    color: var(--text-secondary);
    text-align: center;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
    cursor: pointer;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 28px;
    transition: 0.4s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 3px;
    background-color: white;
    border-radius: 50%;
    transition: 0.4s;
}

input:checked + .slider {
    background-color: var(--slider-bg);
}

input:checked + .slider:before {
    left: calc(100% - 24px);
}

/* --- Side Menu Styles --- */
#menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1900;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease-in-out;
}

body.menu-open #menu-overlay {
    opacity: 1;
    pointer-events: auto;
}

#side-menu {
    position: fixed;
    top: 0;
    right: 0;
    width: 280px;
    height: 100%;
    background-color: var(--bg-secondary);
    box-shadow: -5px 0 15px rgba(0, 0, 0, 0.2);
    transform: translateX(100%);
    transition: transform 0.3s ease-in-out;
    z-index: 2000;
    padding-top: 4rem;
}

body.menu-open #side-menu {
    transform: translateX(0);
}

#side-menu ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.close-menu-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s ease-out;
}

.close-menu-btn div {
    width: 24px;
    height: 24px;
    stroke: var(--text-primary);
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    width: 100%;
    padding: 1rem 1.5rem;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.2rem;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    transition: background-color 0.3s ease-out;
}

.menu-item div {
    width: 24px;
    height: 24px;
    stroke: var(--text-primary);
}

/* --- Saved Entries View Styles --- */
.saved-entries-actions {
    margin-bottom: 1rem;
}

#saved-entries-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    list-style: none;
}

.saved-entry-card {
    background-color: var(--bg-record);
    border-radius: 0.5rem;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.saved-entry-card p {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.saved-entry-card strong {
    color: var(--text-muted);
    font-weight: 600;
}

.saved-entry-card .timestamp {
    font-size: 0.75rem;
    color: var(--text-muted);
    align-self: flex-start;
}

.saved-entry-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.saved-entry-actions .action-btn {
    flex-grow: 1;
}

.saved-entry-actions .delete-btn {
    background-color: var(--accent-danger);
    border-color: var(--accent-danger);
    color: #ffffff;
}

.no-vehicles-message {
    color: var(--text-secondary);
}

/* --- Update Checker --- */
#update-button {
    background: none;
    border: none;
    color: var(--text-primary);
    /* cursor: pointer;
    font-family: inherit;
    font-size: 1.2rem;
    font-weight: 500;
    padding: 1rem;
    text-align: left; */
    flex-grow: 1;
}

#update-button.update-available {
    color: #27ae60;
    font-weight: 700;
}

/* --- Toast Notification Styles --- */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translate(-50%, 150%);
    padding: 1rem 1.5rem;
    border-radius: 0.5rem;
    background-color: #27ae60;
    color: #ffffff;
    font-weight: 500;
    text-align: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    opacity: 0;
    transition:
        transform 0.2s ease-out,
        opacity 0.4s ease-out;
    z-index: 2000;
    pointer-events: none;
    max-width: 90%;
    min-height: fit-content;
}

.toast.active {
    transform: translate(-50%, 0);
    opacity: 1;
    pointer-events: auto;
}

/* Modifier class for error messages */
.toast.error {
    background-color: var(--accent-danger);
}

/* --- Refresh Interval Selector --- */
.menu-setting {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    font-size: 1rem;
    color: var(--text-secondary);
}

select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-color: var(--bg-interactive);
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    color: var(--text-primary);
    padding: 0.5rem 2rem 0.5rem 0.75rem;
    font-family: inherit;
    font-size: 1rem;
    cursor: pointer;
    background-image: url("./img/small-chevron.svg");
    background-position: right 0.5rem center;
    background-repeat: no-repeat;
    background-size: 1.5em 1.5em;
}

#refresh-interval-select:focus {
    outline: none;
    box-shadow: 0 0 0 2px var(--accent-primary);
    border-color: var(--accent-primary);
}

/* --- Interaction State Fixes --- */
#header-buttons button,
.vehicle-card,
#login-button,
.action-btn,
.close-menu-btn,
.toggle-switch,
.back-button,
.form-expander-header,
button {
    -webkit-tap-highlight-color: transparent;
}

/* --- These are the background color of buttons when they're being pushed --- */
#header-buttons button:active,
.card-header:active,
#login-button:active,
.action-btn:active,
.back-button:active,
.close-menu-btn:active,
.form-expander-header:active,
.saved-entry-actions .delete-btn:active {
    background: var(--bg-tertiary) !important;
    transition-duration: 0s !important;
}

@media (hover: hover) and (pointer: fine) {
    #header-buttons button:hover {
        background-color: rgba(236, 240, 241, 0.1);
    }
    .card-header:hover {
        background-color: rgba(255, 255, 255, 0.1);
    }
    #login-button:hover {
        background-color: var(--accent-hover);
    }
    .action-btn:hover {
        background-color: var(--action-button-hover-bg);
    }
    .saved-entry-actions .delete-btn:hover {
        background-color: var(--accent-danger-hover);
        border-color: var(--accent-danger-hover);
    }
}
