/* ── Reset ─────────────────────────────────────────────────────────────── */

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* ── Base ──────────────────────────────────────────────────────────────── */

body {
    font-family: 'Inter', Arial, sans-serif;
    background: #f2f2f2;
    color: #1a1a1a;
    min-height: 100vh;
    overflow-x: hidden; /* prevent page-level horizontal scroll */
}

/* ── Navigation bar ────────────────────────────────────────────────────── */

header {
    background: #FDFAF5;
    border-bottom: 1px solid #e8e4dc;
    padding: 0 2.5rem;
    height: 62px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand h1 {
    font-size: clamp(1.1rem, 3.5vw, 1.5rem);
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1;
}

.nav-brand h1 a {
    color: #1a1a1a;
    text-decoration: none;
}

.nav-brand h1 {
    color: #1a1a1a;
}

.nav-tagline {
    color: #888888;
    font-size: 0.82rem;
    font-weight: 400;
    letter-spacing: 0.01em;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.nav-links a {
    color: #1a1a1a;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    padding: 0.35rem 0.75rem;
    border-radius: 6px;
    transition: background 0.15s, color 0.15s;
    /* Ensure 44px tap target on touch devices */
    min-height: 44px;
    display: inline-flex;
    align-items: center;
}

.nav-links a:hover {
    background: #f0ece3;
    color: #000000;
}

/* ── Main container ────────────────────────────────────────────────────── */

main {
    width: 90%;
    margin: 2rem auto;
    padding: 0 1.25rem 3rem;
}

/* ── Cards ─────────────────────────────────────────────────────────────── */

.card {
    width: 100%;
    background: #FDFAF5;
    color: #1a1a1a;
    border-radius: 10px;
    padding: 0;
    margin-bottom: 1.25rem;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
    overflow: hidden;
}

/* Visualization card — full-bleed: busts out of main's 90% width and padding
   so the chart gets every pixel of horizontal space.
   margin-left: calc(50% - 50vw) shifts the card left by exactly the combined
   offset of main's centering + padding, regardless of screen size. */
.card--viz {
    overflow: hidden;
    width: 100vw;
    margin-left: calc(50% - 50vw);
    margin-right: calc(50% - 50vw);
    border-radius: 0;
}

.card--viz .card-header {
    border-radius: 10px 10px 0 0;
}

.card--viz .js-plotly-plot,
.card--viz .plotly-graph-div {
    display: block;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    margin: 0 auto;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: #f7f6f2;
    border-bottom: 1px solid #e8e6e0;
}

.card h2 {
    font-size: clamp(0.95rem, 2.5vw, 1.1rem);
    font-weight: 700;
    color: #1a1a1a;
    letter-spacing: -0.01em;
}

/* Card body — wraps padded content (used on results page) */
.card-body {
    padding: 1.25rem 1.5rem;
}

/* ── Data table ────────────────────────────────────────────────────────── */

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    padding: 0.55rem 1.5rem;
    text-align: left;
    font-size: 0.72rem;
    font-weight: 600;
    color: #777777;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    background: #f7f6f2;
    border-bottom: 1px solid #e8e6e0;
}

.data-table td {
    padding: 0.45rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid #eeece8;
}

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

.data-table input {
    width: 100%;
    min-width: 0;
    padding: 0.38rem 0.6rem;
    border: 1px solid #d8d8d8;
    border-radius: 5px;
    font-size: 0.9rem;
    font-family: inherit;
    background: #ffffff;
    color: #1a1a1a;
    transition: border-color 0.15s, box-shadow 0.15s;
    min-height: 44px; /* touch-friendly tap target */
}

/* Give text inputs room to show reasonable name lengths */
.data-table input[type="text"] {
    min-width: 80px;
}

/* Number inputs: hide spinners to reclaim the ~18px they reserve,
   keeping the full input width available for the typed value */
.data-table input[type="number"] {
    min-width: 68px;
    
}

.data-table input[type="number"]::-webkit-inner-spin-button,
.data-table input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.data-table input:focus {
    outline: none;
    border-color: #217346;
    box-shadow: 0 0 0 3px rgba(33, 115, 70, 0.12);
}

/* ── Buttons ───────────────────────────────────────────────────────────── */

button {
    cursor: pointer;
    font-family: inherit;
}

/* Primary CTA */
.btn-primary {
    background: #217346;
    color: #ffffff;
    border: none;
    border-radius: 7px;
    padding: 0.85rem 3rem;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    transition: background 0.15s, transform 0.1s;
    min-height: 44px;
}

.btn-primary:hover {
    background: #145c2c;
    transform: translateY(-1px);
}

.btn-primary:disabled {
    background: #5a9e72;
    cursor: not-allowed;
    transform: none;
    opacity: 0.7;
}

/* Add-row + secondary actions */
.btn-add,
.btn-secondary {
    background: #217346;
    color: #ffffff;
    border: none;
    border-radius: 5px;
    padding: 0.38rem 0.85rem;
    font-size: 0.82rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    transition: background 0.15s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none; /* when used as <a> */
    min-height: 44px;
}

.btn-add:hover,
.btn-secondary:hover {
    background: #145c2c;
}

.btn-secondary:disabled {
    background: #5a9e72;
    opacity: 0.45;
    cursor: not-allowed;
}

/* Remove row */
.btn-remove {
    background: transparent;
    color: #c0c0c0;
    border: none;
    font-size: 1.2rem;
    line-height: 1;
    padding: 0 0.4rem;
    transition: color 0.15s;
    min-height: 44px;
    min-width: 44px;
}

.btn-remove:hover {
    color: #e74c3c;
}

/* ── Form actions bar ──────────────────────────────────────────────────── */

.actions {
    text-align: center;
    padding: 1rem 0;
}

/* ── Summary list (results page) ───────────────────────────────────────── */

.summary {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.25rem 1rem;
}

.summary li {
    padding: 0.4rem 0;
    font-size: 0.95rem;
    color: #444444;
}

.summary li strong {
    color: #1a1a1a;
}

/* ── Error / Warning banners ───────────────────────────────────────────── */

.error-banner {
    background: #fdecea;
    color: #b71c1c;
    border: 1px solid #f5c2c0;
    border-radius: 8px;
    padding: 1rem 1.25rem;
    margin-bottom: 1.25rem;
    font-size: 0.92rem;
}

.warning-banner {
    background: #f7f6f2;
    color: #333333;
    border: 1px solid #dddddd;
    border-radius: 6px;
    padding: 0.85rem 1rem;
    margin-top: 1rem;
    font-size: 0.9rem;
}

/* ── Row-count badge ───────────────────────────────────────────────────── */

.row-count {
    font-size: 0.75rem;
    font-weight: 500;
    color: #aaaaaa;
    margin-left: 0.3rem;
}

/* ── Unpacked items list ───────────────────────────────────────────────── */

.unpacked-list {
    list-style: none;
    margin: 0.5rem 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.unpacked-list li {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.88rem;
}

.unpacked-name {
    font-weight: 700;
    color: #1a1a1a;
}

.unpacked-dims {
    color: #777777;
    font-family: 'Courier New', monospace;
    font-size: 0.82rem;
}

.unpacked-qty {
    background: #eeece8;
    color: #444444;
    border-radius: 4px;
    padding: 0.05rem 0.35rem;
    font-size: 0.78rem;
    font-weight: 700;
}

/* ── Results page nav ──────────────────────────────────────────────────── */

.results-nav {
    margin-bottom: 1.25rem;
}

.results-nav--bottom {
    margin-top: 0.5rem;
    margin-bottom: 0;
}

/* ── 3D Viz hint ───────────────────────────────────────────────────────── */

.viz-hint {
    font-size: 0.72rem;
    font-weight: 400;
    color: #aaaaaa;
    margin-left: 0.5rem;
}

/* ── Per-box grid viz layout ───────────────────────────────────────────── */

.viz-flex-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
    padding: 1rem 0 0;
}

.viz-box-item {
    min-width: 0;
}

/* Single chart spans full width */
.viz-box-item:only-child {
    grid-column: 1 / -1;
}

/* ── Viz grid responsive breakpoints ──────────────────────────────────── */

@media (max-width: 1024px) {
    .viz-flex-container {
        grid-template-columns: 1fr;
    }
}

/* ── Carrier preset footer ─────────────────────────────────────────────── */

.add-boxes-heading {
    font-size: 0.9rem;
    font-weight: 700;
    color: #1a1a1a;
    white-space: nowrap;
    margin: 0;
}

.add-boxes-body {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
}

.carrier-controls {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.preset-label {
    font-size: 0.82rem;
    font-weight: 500;
    color: #555555;
    white-space: nowrap;
}

.preset-hint {
    font-size: 0.75rem;
    color: #aaaaaa;
    font-style: italic;
    white-space: nowrap;
}

.preset-select {
    padding: 0.38rem 0.65rem;
    border: 1px solid #d8d8d8;
    border-radius: 5px;
    font-size: 0.88rem;
    font-family: inherit;
    background: #ffffff;
    color: #1a1a1a;
    transition: border-color 0.15s;
    min-height: 44px;
    max-width: 100%;
}

.preset-select:focus {
    outline: none;
    border-color: #217346;
}

#carrier-select  { min-width: 130px; flex: 1 1 130px; }
#box-size-select { flex: 2 1 180px; min-width: 0; }

.preset-select:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    background: #f7f6f2;
}

/* ── Mobile responsive ─────────────────────────────────────────────────── */

@media (max-width: 640px) {
    /* Header: drop fixed height, shrink padding, allow content to wrap */
    header {
        height: auto;
        min-height: 52px;
        padding: 0.5rem 1rem;
        flex-wrap: wrap;
        gap: 0.4rem;
    }

    .nav-links a {
        font-size: 0.8rem;
        padding: 0.25rem 0.5rem;
        min-height: 40px;
    }

    /* Main container: tighter margins */
    main {
        padding: 0 0.75rem 2rem;
        margin: 0.75rem auto;
    }

    /* Primary button: full width on small screens */
    .btn-primary {
        width: 100%;
        padding: 0.85rem 1rem;
    }

    /* Carrier controls: stack vertically */
    .add-boxes-body {
        flex-direction: column;
        align-items: flex-start;
    }

    .carrier-controls {
        width: 100%;
    }

    .preset-hint {
        display: none; /* save horizontal space on mobile */
    }

    /* ── Stacked table layout: editable tables (home page) only ────────── */
    /* Scoped to :has(input) so the read-only results table keeps its header
       and normal row layout on mobile instead of hiding the thead. */

    .data-table:has(input) thead {
        display: none;
    }

    .data-table:has(input),
    .data-table:has(input) tbody {
        display: block;
        width: 100%;
    }

    .data-table:has(input) tr {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0;
        border: 1px solid #e8e6e0;
        border-radius: 8px;
        margin-bottom: 0.75rem;
        background: #fff;
        overflow: hidden;
    }

    .data-table:has(input) td {
        display: flex;
        flex-direction: column;
        padding: 0.5rem 0.75rem;
        border-bottom: 1px solid #f0ece8;
        border-right: 1px solid #f0ece8;
        white-space: normal;
    }

    /* Name cell spans full width */
    .data-table:has(input) td:first-child {
        grid-column: 1 / -1;
        border-right: none;
    }

    /* Remove-button cell spans full width, right-aligned */
    .data-table:has(input) td:last-child {
        grid-column: 1 / -1;
        border-bottom: none;
        border-right: none;
        flex-direction: row;
        justify-content: flex-end;
        padding: 0.25rem 0.75rem;
    }

    /* Label above each input (from data-label attribute) */
    .data-table:has(input) td[data-label]:not([data-label=''])::before {
        content: attr(data-label);
        font-size: 0.68rem;
        font-weight: 600;
        color: #888888;
        text-transform: uppercase;
        letter-spacing: 0.07em;
        margin-bottom: 0.2rem;
    }

    .data-table input {
        width: 100%;
        min-width: 0;
        padding: 0.35rem 0.5rem;
    }

    /* Read-only results table: keep normal table layout,
       scroll horizontally if content is wider than the screen */
    .data-table:not(:has(input)) {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        width: 100%;
    }

    /* Card body: allow inner content to scroll if needed */
    .card-body {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Summary grid: single column on tiny screens */
    .summary {
        grid-template-columns: 1fr;
    }

    /* Viz card: allow horizontal scroll for chart on very small screens */
    .card--viz {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}
