/* =========================================================
   Travel & Expense Report
   Main Application Stylesheet
   ========================================================= */


/* ---------------------------------------------------------
   Global
   --------------------------------------------------------- */

:root {
    font-family:
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;

    color: #172033;
    background: #f4f7fb;
}


* {
    box-sizing: border-box;
}


body {
    margin: 0;

    color: #172033;
    background: #f4f7fb;
}


a {
    color: #1769aa;
}


a:hover {
    color: #12598f;
}


/* ---------------------------------------------------------
   Header
   --------------------------------------------------------- */

header {
    display: flex;

    justify-content: space-between;
    align-items: center;

    gap: 1rem;

    padding:
        1rem
        max(
            1rem,
            calc((100% - 1100px) / 2)
        );

    color: #ffffff;
    background: #173b68;
}


.brand {
    flex-shrink: 0;

    font-size: 1.05rem;
    font-weight: 800;

    white-space: nowrap;
}


.brand,
header a {
    color: #ffffff;

    text-decoration: none;
}


header a:hover {
    color: #ffffff;

    text-decoration: underline;
}


/* ---------------------------------------------------------
   Navigation
   --------------------------------------------------------- */

nav {
    display: flex;

    align-items: center;
    flex-wrap: wrap;

    gap: 1rem;
}


nav > span {
    font-weight: 600;
}


/* ---------------------------------------------------------
   Navigation Profile
   --------------------------------------------------------- */

.nav-profile {
    display: inline-flex;

    flex-direction: row;
    align-items: center;

    width: auto;

    gap: 8px;

    color: #ffffff;

    text-decoration: none;

    white-space: nowrap;
}


.nav-profile:hover {
    color: #ffffff;

    text-decoration: none;
}


/* Uploaded navigation avatar */

header nav .nav-profile img.nav-avatar {
    display: block !important;

    width: 32px !important;
    height: 32px !important;

    min-width: 32px !important;
    min-height: 32px !important;

    max-width: 32px !important;
    max-height: 32px !important;

    flex: 0 0 32px !important;

    padding: 0 !important;
    margin: 0 !important;

    border: 2px solid
        rgba(255, 255, 255, 0.85) !important;

    border-radius: 50% !important;

    object-fit: cover !important;
    object-position: center center !important;

    aspect-ratio: 1 / 1;

    background: #ffffff;

    overflow: hidden !important;
}


/* Initials fallback */

header nav .nav-profile .nav-avatar-initials {
    display: inline-flex !important;

    align-items: center;
    justify-content: center;

    width: 32px !important;
    height: 32px !important;

    min-width: 32px !important;
    min-height: 32px !important;

    max-width: 32px !important;
    max-height: 32px !important;

    flex: 0 0 32px !important;

    padding: 0 !important;
    margin: 0 !important;

    border: 2px solid
        rgba(255, 255, 255, 0.85);

    border-radius: 50% !important;

    font-size: 0.72rem;
    font-weight: 800;
    line-height: 1;

    color: #173b68;
    background: #ffffff;

    overflow: hidden;
}


/* ---------------------------------------------------------
   Main Layout
   --------------------------------------------------------- */

main {
    width: 100%;
    max-width: 1100px;

    min-height: 75vh;

    margin: 2rem auto;

    padding: 0 1rem;
}


h1 {
    margin-top: 0;
    margin-bottom: 1.25rem;
}


h2 {
    margin-top: 0;
    margin-bottom: 1rem;

    font-size: 1.25rem;
}


p {
    line-height: 1.5;
}


/* ---------------------------------------------------------
   Cards
   --------------------------------------------------------- */

.card {
    margin: 1rem 0;

    padding: 1.25rem;

    background: #ffffff;

    border: 1px solid #dce4ef;
    border-radius: 12px;

    box-shadow:
        0 3px 12px
        rgba(25, 50, 74, 0.05);
}


.narrow {
    max-width: 520px;
}


/* ---------------------------------------------------------
   Grid Layout
   --------------------------------------------------------- */

.grid {
    display: grid;

    grid-template-columns:
        repeat(
            auto-fit,
            minmax(210px, 1fr)
        );

    gap: 1rem;
}


/* ---------------------------------------------------------
   Forms
   --------------------------------------------------------- */

label {
    display: block;

    margin: 0.8rem 0;

    font-weight: 650;
}


input,
select,
textarea {
    width: 100%;
    max-width: 100%;
    min-width: 0;

    margin-top: 0.35rem;

    padding: 0.7rem;

    font: inherit;

    color: #172033;
    background: #ffffff;

    border: 1px solid #aebbc9;
    border-radius: 7px;
}


input:focus,
select:focus,
textarea:focus {
    border-color: #1769aa;

    outline: 2px solid
        rgba(23, 105, 170, 0.20);

    outline-offset: 1px;
}


input[readonly] {
    color: #475569;
    background: #edf2f7;

    cursor: not-allowed;
}


textarea {
    min-height: 100px;

    resize: vertical;
}


/* ---------------------------------------------------------
   Checkboxes
   --------------------------------------------------------- */

.checkbox-label {
    display: flex;

    align-items: center;

    gap: 0.6rem;
}


.checkbox-label input {
    width: auto;

    margin: 0;
}


/* ---------------------------------------------------------
   Buttons
   --------------------------------------------------------- */

button,
.button {
    display: inline-block;

    padding: 0.7rem 1rem;

    font: inherit;
    font-weight: 700;

    color: #ffffff;
    background: #1769aa;

    border: 0;
    border-radius: 7px;

    text-decoration: none;

    cursor: pointer;
}


button:hover,
.button:hover {
    color: #ffffff;
    background: #12598f;

    text-decoration: none;
}


button:focus,
.button:focus {
    outline: 2px solid #173b68;

    outline-offset: 2px;
}


/* ---------------------------------------------------------
   Destructive Actions
   --------------------------------------------------------- */

.danger {
    background: #a72828;
}


.danger:hover {
    background: #861f1f;
}


/* ---------------------------------------------------------
   Toolbars
   --------------------------------------------------------- */

.toolbar {
    display: flex;

    align-items: center;
    flex-wrap: wrap;

    gap: 0.7rem;

    margin: 1rem 0;
}


.inline {
    display: inline;
}


/* ---------------------------------------------------------
   Tables
   --------------------------------------------------------- */

.table-wrap {
    width: 100%;

    overflow-x: auto;
}


table {
    width: 100%;

    border-collapse: collapse;

    background: #ffffff;
}


th,
td {
    padding: 0.75rem;

    text-align: left;
    vertical-align: top;

    border-bottom: 1px solid #e3e8ef;

    white-space: nowrap;
}


th {
    font-weight: 700;

    background: #f8fafc;
}


tbody tr:hover {
    background: #f8fafc;
}


tfoot th {
    background: #eef3f8;

    border-top: 2px solid #cbd5e1;
}


.num {
    text-align: right;
}


/* ---------------------------------------------------------
   Expense Description Details
   --------------------------------------------------------- */

.expense-table td[data-label="Description"] {
    min-width: 220px;

    white-space: normal;

    overflow-wrap: anywhere;
}


.expense-table td[data-label="Description"] small {
    line-height: 1.5;
}


/* ---------------------------------------------------------
   Report Status Badges
   --------------------------------------------------------- */

.status {
    display: inline-block;

    padding: 0.25rem 0.6rem;

    font-size: 0.9rem;
    font-weight: 650;

    border-radius: 999px;

    background: #dde5ee;
    color: #334155;

    white-space: nowrap;
}


.status.draft {
    background: #dde5ee;
    color: #334155;
}


.status.submitted {
    background: #fff0c7;
    color: #725400;
}


.status.approved {
    background: #d5f4df;
    color: #146531;
}


.status.returned,
.status.rejected {
    background: #f9d9d9;
    color: #842020;
}


/* ---------------------------------------------------------
   Flash Messages
   --------------------------------------------------------- */

.flash {
    margin: 1rem 0;

    padding: 0.8rem 1rem;

    line-height: 1.45;

    border-radius: 8px;
}


.flash.error {
    color: #842020;
    background: #f9d9d9;

    border: 1px solid #efb8b8;
}


.flash.success {
    color: #146531;
    background: #d5f4df;

    border: 1px solid #a9dfba;
}


/* ---------------------------------------------------------
   Mileage
   --------------------------------------------------------- */

.mileage-fields {
    margin: 1.25rem 0;

    background: #f8fafc;

    border-color: #cbd5e1;
}


.mileage-fields h2 {
    color: #173b68;
}


/* ---------------------------------------------------------
   Expense Receipt Entry
   --------------------------------------------------------- */

.mobile-receipt-section {
    margin: 1.25rem 0;
}


.field-help {
    margin: 0.5rem 0;

    color: #64748b;

    font-size: 0.9rem;
}


.receipt-selected {
    margin-top: 0.75rem;

    padding: 0.7rem;

    color: #146531;
    background: #d5f4df;

    border: 1px solid #a9dfba;
    border-radius: 7px;
}


/* ---------------------------------------------------------
   Receipt Actions
   --------------------------------------------------------- */

.receipt-delete-form {
    display: inline;

    width: auto;
}


.receipt-delete-form .receipt-delete-link {
    display: inline;

    width: auto;
    min-width: 0;

    margin: 0;
    padding: 0;

    font: inherit;
    font-weight: normal;

    color: #a72828;
    background: transparent;

    border: 0;
    border-radius: 0;

    text-decoration: underline;

    cursor: pointer;
}


.receipt-delete-form .receipt-delete-link:hover {
    color: #861f1f;
    background: transparent;

    text-decoration: underline;
}


.receipt-delete-form .receipt-delete-link:focus {
    outline: 2px solid #a72828;

    outline-offset: 2px;
}


/* ---------------------------------------------------------
   Receipt Viewer
   --------------------------------------------------------- */

.receipt-viewer {
    max-width: 900px;
}


.receipt-viewer-header {
    display: flex;

    align-items: flex-start;
    justify-content: space-between;

    gap: 1rem;

    margin-bottom: 1rem;
}


.receipt-viewer-header h2 {
    margin-bottom: 0.25rem;
}


.receipt-viewer-actions {
    margin-top: 0;
}


.receipt-image-container {
    display: flex;

    justify-content: center;

    width: 100%;

    padding: 1rem;

    background: #eef3f8;

    border-radius: 10px;

    overflow: hidden;
}


.receipt-image {
    display: block;

    width: auto;
    max-width: 100%;

    height: auto;
    max-height: 75vh;

    object-fit: contain;

    border-radius: 6px;

    background: #ffffff;
}


.receipt-file-message {
    padding: 2rem 1rem;

    text-align: center;

    background: #f8fafc;

    border: 1px solid #dce4ef;
    border-radius: 10px;
}


/* ---------------------------------------------------------
   Report Comments
   --------------------------------------------------------- */

.report-comment {
    padding: 0.8rem 0;

    border-bottom: 1px solid #e3e8ef;
}


.report-comment:last-child {
    border-bottom: 0;
}


.report-comment p {
    margin-top: 0.4rem;
    margin-bottom: 0.4rem;
}


/* ---------------------------------------------------------
   Reporting Charts
   --------------------------------------------------------- */

.report-chart {
    position: relative;

    width: 100%;
    height: 360px;

    margin-top: 1rem;
    margin-bottom: 2rem;

    padding: 0.5rem;
}


.report-chart canvas {
    max-width: 100%;
}


/* ---------------------------------------------------------
   Audit Pagination
   --------------------------------------------------------- */

.audit-pagination {
    justify-content: center;

    margin-top: 1.25rem;
    margin-bottom: 0;
}


.pagination-button {
    min-width: 42px;

    text-align: center;
}


.pagination-current {
    background: #173b68;

    cursor: default;
}


.pagination-current:hover {
    background: #173b68;
}


.pagination-ellipsis {
    padding: 0.7rem 0.25rem;

    color: #64748b;
}


/* ---------------------------------------------------------
   Profile Page
   --------------------------------------------------------- */

.profile-card {
    position: relative;
}


.profile-edit-button {
    position: absolute;

    top: 12px;
    right: 12px;

    display: inline-flex;

    align-items: center;
    justify-content: center;

    width: 34px;
    height: 34px;
    min-width: 34px;

    padding: 0;

    font-size: 1rem;
    line-height: 1;

    color: #173b68;
    background: #eef3f8;

    border: 1px solid #dce4ef;
    border-radius: 50%;
}


.profile-edit-button:hover {
    color: #ffffff;
    background: #1769aa;
}


.profile-header {
    display: flex;

    align-items: center;

    gap: 1.5rem;

    margin: 1rem 0;
}


.profile-avatar-section {
    display: flex;

    flex: 0 0 auto;

    margin: 0;
}


.profile-avatar {
    display: block;

    width: 96px;
    height: 96px;

    min-width: 96px;
    min-height: 96px;

    max-width: 96px;
    max-height: 96px;

    border: 3px solid #dce4ef;
    border-radius: 50%;

    object-fit: cover;
    object-position: center;

    background: #ffffff;

    box-shadow:
        0 3px 12px
        rgba(25, 50, 74, 0.12);

    overflow: hidden;
}


.profile-avatar-initials {
    display: flex;

    align-items: center;
    justify-content: center;

    font-size: 1.7rem;
    font-weight: 800;

    color: #ffffff;
    background: #1769aa;
}


.profile-details {
    flex: 1;

    min-width: 0;

    margin: 0;
}


.profile-details p {
    margin: 0.4rem 0;
}


/* ---------------------------------------------------------
   Footer
   --------------------------------------------------------- */

footer {
    padding: 2rem 1rem;

    text-align: center;

    color: #667085;
}


/* =========================================================
   Responsive Styles
   ========================================================= */


/* ---------------------------------------------------------
   Tablet / Mobile
   --------------------------------------------------------- */

@media (max-width: 750px) {

    header {
        flex-direction: column;

        align-items: flex-start;
    }


    nav {
        width: 100%;
    }


    main {
        margin-top: 1rem;
    }


    /* Keep grids and form controls inside cards */

    .grid {
        grid-template-columns:
            minmax(0, 1fr);
    }


    .grid > * {
        min-width: 0;
        max-width: 100%;
    }


    .card form,
    .card label {
        min-width: 0;
        max-width: 100%;
    }


    .card input,
    .card select,
    .card textarea {
        width: 100%;
        min-width: 0;
        max-width: 100%;
    }


    /* iPhone / Safari date controls */

    .card input[type="date"] {
        display: block;

        width: 100%;
        min-width: 0;
        max-width: 100%;

        -webkit-appearance: none;
        appearance: none;
    }


    .card {
        padding: 1rem;
    }


    .toolbar {
        align-items: stretch;
    }


    .report-chart {
        height: 320px;
    }


    /* -----------------------------------------------------
       Mobile Receipt Viewer
       ----------------------------------------------------- */

    .receipt-viewer {
        padding: 0.75rem;
    }


    .receipt-viewer-header {
        flex-direction: column;

        gap: 0.5rem;
    }


    .receipt-viewer-actions {
        display: grid;

        grid-template-columns:
            1fr
            1fr;

        width: 100%;
    }


    .receipt-image-container {
        padding: 0.5rem;
    }


    .receipt-image {
        width: 100%;
        max-width: 100%;

        height: auto;

        max-height: none;
    }


    /* -----------------------------------------------------
       Mobile Add Expense Form
       ----------------------------------------------------- */

    .expense-entry-form {
        padding: 1rem;
    }


    .expense-entry-form .grid {
        grid-template-columns: 1fr;
    }


    .expense-entry-form input,
    .expense-entry-form select,
    .expense-entry-form textarea {
        min-height: 48px;

        font-size: 16px;
    }


    .expense-entry-form input[type="file"] {
        min-height: auto;

        padding: 0.9rem;
    }


    .expense-entry-form button,
    .expense-entry-form .button {
        min-height: 48px;

        font-size: 1rem;
    }


    .mobile-receipt-section {
        padding: 1rem;

        background: #f8fafc;

        border: 1px solid #dce4ef;
        border-radius: 10px;
    }


    /* -----------------------------------------------------
       Sticky Add Expense Actions
       ----------------------------------------------------- */

    .expense-mobile-actions {
        position: sticky;

        bottom: 0;

        z-index: 20;

        display: grid;

        grid-template-columns:
            1fr
            1fr;

        gap: 0.75rem;

        margin:
            1rem
            -1rem
            -1rem;

        padding:
            0.85rem
            1rem
            calc(
                0.85rem
                + env(safe-area-inset-bottom)
            );

        background:
            rgba(
                255,
                255,
                255,
                0.97
            );

        border-top: 1px solid #dce4ef;

        box-shadow:
            0 -4px 12px
            rgba(
                25,
                50,
                74,
                0.08
            );
    }


    .expense-mobile-actions button,
    .expense-mobile-actions .button {
        width: 100%;

        margin: 0;

        text-align: center;
    }


    /* -----------------------------------------------------
       Mobile Expense Report Table
       ----------------------------------------------------- */

    .expense-table-wrap {
        overflow: visible;
    }


    .expense-table {
        display: block;

        background: transparent;
    }


    .expense-table thead {
        display: none;
    }


    .expense-table tbody {
        display: block;
    }


    .expense-table tbody tr {
        display: block;

        margin-bottom: 1rem;

        padding: 0.9rem;

        background: #ffffff;

        border: 1px solid #dce4ef;
        border-radius: 10px;

        box-shadow:
            0 2px 8px
            rgba(25, 50, 74, 0.05);
    }


    .expense-table tbody td {
        display: grid;

        grid-template-columns:
            minmax(90px, 35%)
            1fr;

        gap: 0.75rem;

        width: 100%;

        padding: 0.55rem 0;

        white-space: normal;

        border-bottom: 1px solid #edf2f7;

        text-align: left;
    }


    .expense-table tbody td:last-child {
        border-bottom: 0;
    }


    .expense-table tbody td::before {
        content: attr(data-label);

        font-weight: 700;

        color: #475569;
    }


    .expense-table tbody td.num {
        text-align: left;
    }


    /* Mobile report total */

    .expense-table .expense-report-total {
        display: flex;

        align-items: center;
        justify-content: space-between;

        gap: 1rem;

        padding: 1rem;

        background: #eef3f8;

        border: 2px solid #cbd5e1;
    }


    .expense-table .expense-report-total th {
        display: block;

        padding: 0;

        border: 0;

        background: transparent;
    }


    .expense-table .expense-report-total th[colspan] {
        flex: 1;
    }


    .expense-table .expense-report-total .num {
        flex: 0 0 auto;

        font-size: 1.1rem;

        color: #173b68;
    }


    .expense-table .expense-report-total th:last-child {
        display: none;
    }


    /* -----------------------------------------------------
       Profile
       ----------------------------------------------------- */

    .profile-header {
        align-items: flex-start;

        gap: 1rem;
    }


    .profile-avatar {
        width: 96px;
        height: 96px;
    }


    .profile-details {
        min-width: 0;
    }
}


/* ---------------------------------------------------------
   Small Phones
   --------------------------------------------------------- */

@media (max-width: 480px) {

    main {
        padding: 0 0.75rem;
    }


    .grid {
        grid-template-columns: 1fr;
    }


    .receipt-viewer-actions {
        grid-template-columns: 1fr;
    }


    button,
    .button {
        width: 100%;

        text-align: center;
    }


    .toolbar {
        flex-direction: column;

        width: 100%;
    }


    /*
     * Keep Add Expense and Cancel side-by-side.
     */

    .expense-mobile-actions {
        display: grid;

        grid-template-columns:
            1fr
            1fr;

        width: auto;

        flex-direction: unset;
    }


    .expense-mobile-actions button,
    .expense-mobile-actions .button {
        width: 100%;

        margin: 0;

        text-align: center;
    }


    .inline {
        display: block;

        width: 100%;
    }


    .inline button {
        width: 100%;
    }


    /*
     * Keep Delete Receipt looking like a text link
     * despite the generic mobile button rules.
     */

    .receipt-delete-form {
        display: inline;

        width: auto;
    }


    .receipt-delete-form .receipt-delete-link {
        display: inline;

        width: auto;

        min-width: 0;

        margin: 0;
        padding: 0;
    }


    .report-chart {
        height: 280px;

        padding: 0;
    }


    /* Keep audit pagination compact */

    .audit-pagination {
        flex-direction: row;

        justify-content: center;
    }


    .audit-pagination .button {
        width: auto;
    }


    .pagination-button {
        min-width: 40px;
    }


    /* Profile stays horizontal */

    .profile-header {
        display: flex;

        flex-direction: row;

        align-items: flex-start;

        gap: 0.8rem;
    }


    .profile-avatar {
        width: 80px;
        height: 80px;

        min-width: 80px;
        min-height: 80px;

        max-width: 80px;
        max-height: 80px;
    }


    .profile-avatar-initials {
        font-size: 1.4rem;
    }


    /* Keep avatar beside username */

    .nav-profile {
        width: auto;

        flex-direction: row;
        align-items: center;
    }


    /* Expense cards use a compact label column */

    .expense-table tbody td {
        grid-template-columns:
            minmax(82px, 32%)
            1fr;

        gap: 0.6rem;
    }
}