/* =========================================
   BUS 20 — MOBILE FIRST STYLES
========================================= */

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --background: #f4f5f7;
    --card: #ffffff;
    --border: #dfe3e8;
    --text: #20242a;
    --muted: #6b7280;

    --primary: #8b1e2d;
    --primary-dark: #681520;
    --gold: #c9a227;

    --yes: #207a45;
    --no: #b42318;
    --na: #667085;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    background: var(--background);
    color: var(--text);

    font-family:
        -apple-system,
        BlinkMacSystemFont,
        "SF Pro Display",
        "SF Pro Text",
        "Segoe UI",
        Roboto,
        Arial,
        sans-serif;

    min-height: 100vh;
}


/* =========================================
   TOP BAR
========================================= */

.topbar {
    position: sticky;
    top: 0;
    z-index: 500;

    background: var(--primary);
    color: white;

    min-height: 68px;

    padding:
        max(10px, env(safe-area-inset-top))
        14px
        10px
        14px;

    display: flex;
    align-items: center;
    justify-content: space-between;

    gap: 10px;

    box-shadow:
        0 2px 10px rgba(0, 0, 0, 0.15);
}

.topbar h1 {
    margin: 0;
    font-size: 22px;
    line-height: 1.1;
    font-weight: 750;
}

.topbar p {
    margin: 3px 0 0;

    font-size: 12px;

    opacity: 0.85;
}


/* =========================================
   LOG BUTTON
========================================= */

.log-button {
    border: none;

    background: var(--gold);
    color: #171717;

    min-height: 44px;

    padding: 0 14px;

    border-radius: 9px;

    font-size: 14px;
    font-weight: 750;

    white-space: nowrap;

    cursor: pointer;

    touch-action: manipulation;
}

.log-button:active {
    transform: scale(0.97);
}


/* =========================================
   MAIN CONTAINER
========================================= */

.container {
    width: 100%;
    max-width: 1200px;

    margin: 0 auto;

    padding: 12px 12px 40px;
}


/* =========================================
   AREA TABS
========================================= */

.area-tabs {
    display: flex;

    gap: 7px;

    overflow-x: auto;
    overflow-y: hidden;

    padding: 2px 2px 12px;

    margin: 0;

    scrollbar-width: none;

    -webkit-overflow-scrolling: touch;
}

.area-tabs::-webkit-scrollbar {
    display: none;
}

.area-tab {
    flex: 0 0 auto;

    min-height: 43px;

    padding: 0 17px;

    border: 1px solid var(--border);

    background: white;
    color: var(--text);

    border-radius: 9px;

    font-size: 14px;
    font-weight: 700;

    white-space: nowrap;

    cursor: pointer;

    touch-action: manipulation;

    box-shadow:
        0 1px 2px rgba(0, 0, 0, 0.03);
}

.area-tab:active {
    transform: scale(0.96);
}

.area-tab.active {
    background: var(--primary);
    color: white;

    border-color: var(--primary);

    box-shadow:
        0 2px 5px rgba(139, 30, 45, 0.25);
}


/* =========================================
   AREA HEADER
========================================= */

.area-header {
    background: var(--card);

    border: 1px solid var(--border);

    border-radius: 12px 12px 0 0;

    padding: 15px;

    display: flex;

    align-items: center;
    justify-content: space-between;

    gap: 12px;
}

.area-header h2 {
    margin: 0;

    font-size: 20px;
    line-height: 1.2;
}

.area-header p {
    margin: 4px 0 0;

    color: var(--muted);

    font-size: 13px;
}

.add-button {
    flex-shrink: 0;

    min-height: 43px;

    padding: 0 14px;

    background: var(--primary);
    color: white;

    border: none;
    border-radius: 9px;

    font-size: 14px;
    font-weight: 700;

    cursor: pointer;

    touch-action: manipulation;
}

.add-button:active {
    transform: scale(0.96);
}


/* =========================================
   TABLE WRAPPER
========================================= */

.table-wrapper {
    background: white;

    border: 1px solid var(--border);
    border-top: none;

    border-radius: 0 0 12px 12px;

    overflow: hidden;
}


/* =========================================
   DESKTOP TABLE
========================================= */

table {
    width: 100%;

    border-collapse: collapse;

    min-width: 900px;
}

th {
    background: #f8f9fa;

    color: #4b5563;

    text-align: left;

    font-size: 13px;
    font-weight: 700;

    padding: 13px 12px;

    border-bottom: 1px solid var(--border);

    white-space: nowrap;
}

td {
    padding: 12px;

    border-bottom: 1px solid var(--border);

    vertical-align: middle;

    font-size: 14px;
}

tbody tr:last-child td {
    border-bottom: none;
}

.check-column {
    width: 62px;

    text-align: center;
}


/* =========================================
   CHECK BUTTONS
========================================= */

.check-button {
    width: 40px;
    height: 40px;

    display: inline-flex;

    align-items: center;
    justify-content: center;

    border: 2px solid var(--border);

    background: white;

    border-radius: 9px;

    font-size: 19px;
    font-weight: 800;

    cursor: pointer;

    touch-action: manipulation;
}

.check-button:active {
    transform: scale(0.90);
}

.check-button.selected.yes {
    background: var(--yes);

    border-color: var(--yes);

    color: white;
}

.check-button.selected.no {
    background: var(--no);

    border-color: var(--no);

    color: white;
}

.check-button.selected.na {
    background: var(--na);

    border-color: var(--na);

    color: white;
}


/* =========================================
   EDIT / DELETE
========================================= */

.edit-button,
.delete-button {
    min-width: 40px;
    min-height: 40px;

    border: none;
    background: transparent;

    font-size: 19px;

    cursor: pointer;

    touch-action: manipulation;
}

.edit-button {
    color: var(--primary);
}

.delete-button {
    color: var(--no);
}

.edit-button:active,
.delete-button:active {
    transform: scale(0.88);
}


/* =========================================
   EMPTY STATE
========================================= */

.empty-message {
    text-align: center;

    color: var(--muted);

    padding: 42px 20px;

    font-size: 14px;

    line-height: 1.7;
}


/* =========================================
   HISTORY
========================================= */

.history-section {
    margin-top: 25px;
}

.section-title {
    background: white;

    border: 1px solid var(--border);

    border-radius: 12px 12px 0 0;

    padding: 16px;
}

.section-title h2 {
    margin: 0;

    font-size: 20px;
}

.section-title p {
    margin: 4px 0 0;

    color: var(--muted);

    font-size: 13px;
}

.history-list {
    background: white;

    border: 1px solid var(--border);
    border-top: none;

    border-radius: 0 0 12px 12px;

    overflow: hidden;
}

.history-item {
    padding: 16px;

    border-bottom: 1px solid var(--border);

    display: flex;

    align-items: center;
    justify-content: space-between;

    gap: 12px;
}

.history-item:last-child {
    border-bottom: none;
}

.history-info {
    min-width: 0;
}

.history-info strong {
    display: block;

    margin-bottom: 5px;

    font-size: 15px;
}

.history-info span {
    color: var(--muted);

    font-size: 12px;

    line-height: 1.5;
}

.view-history-button {
    flex-shrink: 0;

    min-height: 40px;

    padding: 0 13px;

    border: 1px solid var(--primary);

    background: white;

    color: var(--primary);

    border-radius: 8px;

    font-size: 13px;
    font-weight: 700;

    cursor: pointer;

    touch-action: manipulation;
}

.view-history-button:active {
    transform: scale(0.95);
}

.no-history {
    padding: 30px 20px;

    text-align: center;

    color: var(--muted);

    font-size: 14px;
}


/* =========================================
   MODAL BACKDROP
========================================= */

.modal {
    position: fixed;

    inset: 0;

    z-index: 1000;

    background: rgba(0, 0, 0, 0.50);

    display: flex;

    align-items: flex-end;
    justify-content: center;

    padding: 0;
}

.modal.hidden {
    display: none;
}


/* =========================================
   MOBILE MODAL
========================================= */

.modal-content {
    width: 100%;

    max-width: 600px;

    max-height: 92vh;

    overflow-y: auto;

    background: white;

    border-radius: 18px 18px 0 0;

    padding:
        20px
        18px
        max(24px, env(safe-area-inset-bottom));

    box-shadow:
        0 -10px 40px rgba(0, 0, 0, 0.25);

    animation: slideUp 0.18s ease-out;
}

@keyframes slideUp {

    from {
        transform: translateY(30px);
        opacity: 0.5;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.small-modal {
    max-width: 500px;
}

.history-modal {
    max-width: 1000px;
    max-height: 94vh;
}


/* =========================================
   MODAL HEADER
========================================= */

.modal-header {
    display: flex;

    justify-content: space-between;
    align-items: flex-start;

    gap: 15px;

    margin-bottom: 20px;
}

.modal-header h2 {
    margin: 0;

    font-size: 21px;
}

.modal-header p {
    margin: 4px 0 0;

    color: var(--muted);

    font-size: 13px;
}

.close-button {
    flex-shrink: 0;

    width: 42px;
    height: 42px;

    border: none;

    background: #f0f1f3;

    border-radius: 50%;

    color: #555;

    font-size: 28px;

    line-height: 1;

    cursor: pointer;

    touch-action: manipulation;
}


/* =========================================
   FORM
========================================= */

label {
    display: block;

    margin-bottom: 17px;

    font-size: 14px;

    font-weight: 700;
}

label input {
    display: block;

    width: 100%;

    min-height: 50px;

    margin-top: 7px;

    padding: 0 13px;

    border: 1px solid #cfd4da;

    border-radius: 9px;

    background: white;

    color: var(--text);

    font-size: 16px;

    outline: none;

    /*
       16px prevents iPhone Safari
       from automatically zooming.
    */
}

label input:focus {
    border-color: var(--primary);

    box-shadow:
        0 0 0 3px rgba(139, 30, 45, 0.10);
}


/* =========================================
   MODAL BUTTONS
========================================= */

.modal-actions {
    display: flex;

    gap: 10px;

    margin-top: 22px;
}

.modal-actions button {
    flex: 1;

    min-height: 50px;

    border-radius: 9px;

    font-size: 15px;

    font-weight: 700;

    cursor: pointer;

    touch-action: manipulation;
}

.primary-button {
    background: var(--primary);

    color: white;

    border: none;
}

.secondary-button {
    background: white;

    color: var(--text);

    border: 1px solid var(--border);
}

.modal-actions button:active {
    transform: scale(0.98);
}

.warning-text {
    color: var(--primary);

    font-weight: 700;

    line-height: 1.5;
}


/* =========================================
   HISTORY DETAILS
========================================= */

.history-area {
    margin-bottom: 25px;
}

.history-area h3 {
    margin: 0 0 10px;

    font-size: 17px;
}

.history-area > div {
    overflow-x: auto;

    -webkit-overflow-scrolling: touch;
}

.history-table {
    width: 100%;

    min-width: 750px;

    border-collapse: collapse;
}

.history-table th,
.history-table td {
    border: 1px solid var(--border);
}

.history-check {
    text-align: center;

    font-weight: 800;
}

.actual-checkbox {
    width: 24px;
    height: 24px;

    cursor: pointer;

    accent-color: var(--primary);
}


/* =========================================
   IPHONE-SIZED SCREENS
========================================= */

@media (max-width: 600px) {

    /*
       Convert the current week's
       table into mobile rider cards.
    */

    .table-wrapper {
        background: transparent;

        border: none;

        overflow: visible;
    }

    table {
        min-width: 0;

        display: block;
    }

    thead {
        display: none;
    }

    tbody {
        display: block;
    }

    tbody tr {
        display: block;

        background: white;

        border: 1px solid var(--border);

        border-radius: 12px;

        margin-bottom: 12px;

        padding: 14px;

        box-shadow:
            0 1px 3px rgba(0, 0, 0, 0.04);
    }

    tbody td {
        display: block;

        border: none;

        padding: 2px 0;

        font-size: 14px;
    }

    /*
       Address
    */

    tbody td:nth-child(1) {
        font-size: 17px;

        font-weight: 750;

        margin-bottom: 3px;
    }

    /*
       Rider
    */

    tbody td:nth-child(2) {
        font-size: 15px;

        font-weight: 650;
    }

    /*
       Parent
    */

    tbody td:nth-child(3),
    tbody td:nth-child(4) {
        color: var(--muted);

        font-size: 13px;
    }

    /*
       Yes / No / N/A row
    */

    tbody td:nth-child(5),
    tbody td:nth-child(6),
    tbody td:nth-child(7) {

        display: inline-flex;

        width: 32%;

        margin-top: 13px;

        justify-content: center;

        align-items: center;
    }

    tbody td:nth-child(5)::before {
        content: "YES";

        margin-right: 6px;

        font-size: 11px;

        font-weight: 800;

        color: var(--yes);
    }

    tbody td:nth-child(6)::before {
        content: "NO";

        margin-right: 6px;

        font-size: 11px;

        font-weight: 800;

        color: var(--no);
    }

    tbody td:nth-child(7)::before {
        content: "N/A";

        margin-right: 6px;

        font-size: 11px;

        font-weight: 800;

        color: var(--na);
    }

    /*
       Edit/Delete row
    */

    tbody td:nth-child(8) {
        display: flex;

        justify-content: flex-end;

        gap: 4px;

        border-top: 1px solid var(--border);

        margin-top: 10px;

        padding-top: 8px;
    }

    .check-button {
        width: 42px;
        height: 42px;
    }

    /*
       Make phone number easy to tap
    */

    tbody td:nth-child(4) {
        padding-top: 2px;
    }

    .empty-message {
        background: white;

        border: 1px solid var(--border);

        border-radius: 12px;

        margin-bottom: 12px;
    }

    /*
       History items stack better.
    */

    .history-item {
        align-items: flex-start;
    }

    /*
       Area header
    */

    .area-header {
        padding: 13px;
    }

    /*
       Keep the add button readable.
    */

    .add-button {
        font-size: 13px;

        padding: 0 12px;
    }
}


/* =========================================
   VERY SMALL IPHONES
========================================= */

@media (max-width: 380px) {

    .topbar {
        padding-left: 10px;
        padding-right: 10px;
    }

    .topbar h1 {
        font-size: 20px;
    }

    .topbar p {
        font-size: 11px;
    }

    .log-button {
        padding: 0 10px;

        font-size: 12px;
    }

    .area-tab {
        padding: 0 14px;
    }

    .area-header h2 {
        font-size: 18px;
    }

    .area-header p {
        font-size: 12px;
    }

    .add-button {
        padding: 0 10px;

        font-size: 12px;
    }
}


/* =========================================
   IPHONE LANDSCAPE
========================================= */

@media (max-width: 900px) and (orientation: landscape) {

    .topbar {
        min-height: 58px;
    }

    .modal-content {
        max-height: 96vh;
    }
}


/* =========================================
   REDUCE MOTION
========================================= */

@media (prefers-reduced-motion: reduce) {

    html {
        scroll-behavior: auto;
    }

    .modal-content {
        animation: none;
    }

    * {
        transition: none !important;
    }
}