/* LJFence layout estimator.
 *
 * Built for a phone held in one hand: the canvas takes the room it can get, the
 * things you tap live at the bottom within thumb reach, and every target is at
 * least 44px. Desktop gets the same layout with more space around it.
 */

:root {
    --est-green: #2f6b3f;
    --est-green-dark: #22522f;
    --est-amber: #d97706;
    --est-line: #e3e8e5;
    --est-ink: #243b2c;
    --est-muted: #6f7b74;
    --est-bg: #f7f9f8;
    --est-bar-h: 132px;
}

.est-page {
    margin: 0;
    background: var(--est-bg);
    color: var(--est-ink);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    /* Lock the page: the canvas pans, the document must not rubber-band. */
    height: 100dvh;
    width: 100%;
    max-width: 100vw;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    overscroll-behavior: none;
}

/* Nothing in the estimator should ever widen the page: the canvas is what
   pans, and a sideways-scrolling document would put the action buttons out of
   reach on a phone. */
.est-page > * { min-width: 0; }

/* ---------- top bar ---------- */

.est-top {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: #fff;
    border-bottom: 1px solid var(--est-line);
    flex: 0 0 auto;
}

.est-top h1 {
    font-size: 1rem;
    font-weight: 700;
    margin: 0;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.est-back,
.est-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    border: 0;
    background: transparent;
    color: var(--est-ink);
    font-size: 1.25rem;
    border-radius: 12px;
    cursor: pointer;
    text-decoration: none;
}

.est-icon-btn:disabled {
    opacity: .3;
    cursor: default;
}

.est-icon-btn:not(:disabled):active {
    background: #eef2ef;
}

/* ---------- canvas ---------- */

.est-stage {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    background:
        radial-gradient(circle at 30% 20%, #ffffff 0%, #f2f6f3 100%);
}

#canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none; /* we handle pan and pinch ourselves */
}

.est-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--est-muted);
    font-size: .9rem;
    background: rgba(247, 249, 248, .85);
}

.est-stage-actions {
    position: absolute;
    top: 12px;
    right: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    /* Above .est-list, or the list would cover the very button that closes it
       and there would be no way back to the drawing. */
    z-index: 6;
}

.est-stage-actions button {
    min-width: 44px;
    min-height: 44px;
    border-radius: 12px;
    border: 1px solid var(--est-line);
    background: rgba(255, 255, 255, .95);
    color: var(--est-ink);
    font-size: .78rem;
    font-weight: 600;
    cursor: pointer;
    padding: 6px 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .06);
}

.est-stage-actions button:active {
    background: #eef2ef;
}

/* ---------- segment chips ---------- */

.est-chips {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 10px 14px;
    background: #fff;
    border-top: 1px solid var(--est-line);
    flex: 0 0 auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.est-chips::-webkit-scrollbar { display: none; }

.chip {
    display: inline-flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    flex: 0 0 auto;
    min-height: 44px;
    padding: 6px 12px;
    border-radius: 12px;
    border: 1px solid var(--est-line);
    background: #f4f7f5;
    cursor: pointer;
    text-align: left;
    max-width: 190px;
}

.chip-gate {
    background: #fff7ed;
    border-color: #fed7aa;
}

.chip-name {
    font-size: .72rem;
    color: var(--est-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 165px;
}

.chip-len {
    font-size: .95rem;
    font-weight: 700;
}

.chips-empty {
    color: var(--est-muted);
    font-size: .85rem;
    padding: 12px 0;
}

/* ---------- bottom bar ---------- */

.est-bar {
    flex: 0 0 auto;
    background: #fff;
    border-top: 1px solid var(--est-line);
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
    display: grid;
    gap: 8px;
}

.est-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    font-size: .88rem;
    color: var(--est-muted);
    min-height: 24px;
}

.est-summary strong { color: var(--est-ink); }

/* Columns follow the number of buttons: the materials page has two, the
   installation page adds a third for job details.
   minmax(0, 1fr) rather than 1fr - a bare 1fr means minmax(auto, 1fr), which
   refuses to shrink below the button text and pushes the whole page sideways
   on a narrow phone. */
.est-actions {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    gap: 8px;
}

.est-actions button {
    min-height: 48px;
    border-radius: 12px;
    border: 1px solid var(--est-line);
    background: #f4f7f5;
    font-size: .9rem;
    font-weight: 600;
    color: var(--est-ink);
    cursor: pointer;
}

.est-actions button:active { background: #e7ede9; }

.btn-primary-lg,
.est-continue {
    min-height: 52px;
    width: 100%;
    border: 0;
    border-radius: 12px;
    background: var(--est-green);
    color: #fff;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
}

.est-continue:disabled {
    background: #c7d2cb;
    cursor: default;
}

.btn-primary-lg:active,
.est-continue:not(:disabled):active { background: var(--est-green-dark); }

.btn-secondary-lg {
    min-height: 48px;
    width: 100%;
    border: 1px solid var(--est-line);
    border-radius: 12px;
    background: #f4f7f5;
    font-weight: 600;
    color: var(--est-ink);
    cursor: pointer;
    margin-top: 10px;
}

.btn-danger-lg {
    min-height: 48px;
    width: 100%;
    border: 1px solid #f3c9c9;
    border-radius: 12px;
    background: #fff5f5;
    color: #b02a2a;
    font-weight: 600;
    cursor: pointer;
    margin-top: 10px;
}

/* ---------- bottom sheet ---------- */

.est-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 60;
    background: #fff;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, .18);
    transform: translateY(102%);
    transition: transform .22s ease;
    max-height: 88dvh;
    display: flex;
    flex-direction: column;
}

.est-sheet.open { transform: translateY(0); }

.est-sheet-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--est-line);
}

.est-sheet-head h2 {
    margin: 0;
    flex: 1;
    font-size: 1.05rem;
    font-weight: 700;
    text-align: center;
}

.est-sheet-body {
    padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.sheet-note {
    color: var(--est-muted);
    font-size: .9rem;
    margin: 0 0 14px;
}

.sheet-note.small { font-size: .82rem; margin-top: 12px; }

/* tiles - one decision per screenful, everything big enough for a thumb */

.tile-grid {
    display: grid;
    gap: 10px;
}

.tile {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
    width: 100%;
    min-height: 64px;
    padding: 14px 16px;
    border: 1px solid var(--est-line);
    border-radius: 14px;
    background: #f7faf8;
    text-align: left;
    cursor: pointer;
}

.tile:active { background: #eaf1ec; border-color: var(--est-green); }

.tile-title { font-size: 1rem; font-weight: 700; }
.tile-hint { font-size: .82rem; color: var(--est-muted); }

.swatch-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 10px;
}

.swatch {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 56px;
    padding: 10px 14px;
    border: 1px solid var(--est-line);
    border-radius: 14px;
    background: #f7faf8;
    font-size: .95rem;
    font-weight: 600;
    cursor: pointer;
}

.swatch:active { border-color: var(--est-green); }

.swatch-dot {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, .15);
    flex: 0 0 auto;
}

/* length entry */

.len-row {
    display: grid;
    grid-template-columns: 64px 1fr 64px;
    gap: 10px;
    align-items: center;
}

.len-step {
    height: 64px;
    border-radius: 14px;
    border: 1px solid var(--est-line);
    background: #f4f7f5;
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--est-ink);
    cursor: pointer;
}

.len-step:active { background: #e7ede9; }

.len-input {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 6px;
    height: 64px;
    border: 1px solid var(--est-line);
    border-radius: 14px;
    background: #fff;
}

.len-input input {
    width: 100%;
    border: 0;
    outline: none;
    font-size: 2rem;
    font-weight: 700;
    text-align: right;
    background: transparent;
    color: var(--est-ink);
    -moz-appearance: textfield;
}

.len-input input::-webkit-outer-spin-button,
.len-input input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.len-input span { font-size: 1rem; color: var(--est-muted); padding-right: 14px; }

.len-in {
    margin: 12px 0 18px;
    color: var(--est-muted);
    font-size: .92rem;
}

.len-in input {
    width: 68px;
    min-height: 44px;
    text-align: center;
    font-size: 1rem;
    border: 1px solid var(--est-line);
    border-radius: 10px;
    background: #fff;
    color: var(--est-ink);
}

/* direction */

.dir-grid {
    display: grid;
    gap: 10px;
}

.dir {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 60px;
    padding: 12px 16px;
    border: 1px solid var(--est-line);
    border-radius: 14px;
    background: #f7faf8;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
}

.dir:active { border-color: var(--est-green); background: #eaf1ec; }

.dir-ico { font-size: 1.5rem; color: var(--est-green); }

.angle-custom {
    margin-top: 22px;
    padding-top: 18px;
    border-top: 1px solid var(--est-line);
}

.angle-custom label {
    display: block;
    font-size: .9rem;
    color: var(--est-muted);
    margin-bottom: 8px;
}

.angle-custom input[type=range] { width: 100%; height: 44px; }

.angle-custom output {
    display: block;
    text-align: center;
    font-weight: 700;
    font-size: 1.1rem;
}

/* list view */

.est-list {
    display: none;
    position: absolute;
    inset: 0;
    background: #fff;
    overflow-y: auto;
    padding: 16px;
    z-index: 5;
}

.est-list.open { display: block; }

.list-run h4 {
    font-size: .95rem;
    margin: 18px 0 8px;
    color: var(--est-green);
}

.list-run:first-child h4 { margin-top: 0; }

.list-run ul { list-style: none; margin: 0; padding: 0; }

.list-run li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    min-height: 52px;
    padding: 8px 12px;
    border: 1px solid var(--est-line);
    border-radius: 10px;
    margin-bottom: 8px;
    cursor: pointer;
    background: #f9fbfa;
}

.badge-closed {
    font-size: .7rem;
    font-weight: 600;
    background: #eaf1ec;
    color: var(--est-green);
    padding: 2px 8px;
    border-radius: 999px;
}

/* ---------- contact / confirmation pages ---------- */

.est-scroll {
    height: 100dvh;
    overflow-y: auto;
    background: var(--est-bg);
    display: block;
}

.est-form {
    max-width: 560px;
    margin: 0 auto;
    padding: 18px 16px calc(40px + env(safe-area-inset-bottom));
}

.est-card {
    background: #fff;
    border: 1px solid var(--est-line);
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 16px;
}

.est-card h2 {
    font-size: 1rem;
    font-weight: 700;
    margin: 0 0 12px;
}

.est-preview {
    width: 100%;
    height: 220px;
    border-radius: 12px;
    background: #f2f6f3;
    display: block;
    touch-action: none;
}

.est-field { margin-bottom: 14px; }

.est-field label {
    display: block;
    font-size: .88rem;
    font-weight: 600;
    margin-bottom: 6px;
}

.est-field .hint {
    font-weight: 400;
    color: var(--est-muted);
}

.est-field input,
.est-field textarea,
.est-field select {
    width: 100%;
    min-height: 50px;
    padding: 12px 14px;
    font-size: 1rem;
    border: 1px solid var(--est-line);
    border-radius: 12px;
    background: #fff;
    color: var(--est-ink);
}

.est-field input:focus,
.est-field textarea:focus {
    outline: 2px solid rgba(47, 107, 63, .35);
    border-color: var(--est-green);
}

.est-field textarea { min-height: 90px; resize: vertical; }

.est-check {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 50px;
    font-size: .95rem;
}

.est-check input {
    width: 24px;
    height: 24px;
    flex: 0 0 auto;
}

.est-error {
    background: #fff5f5;
    border: 1px solid #f3c9c9;
    color: #b02a2a;
    padding: 12px 14px;
    border-radius: 12px;
    font-size: .9rem;
    margin-bottom: 14px;
}

.est-summary-list {
    list-style: none;
    margin: 0;
    padding: 0;
    font-size: .92rem;
}

.est-summary-list li {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 0;
    border-bottom: 1px solid var(--est-line);
}

.est-summary-list li:last-child { border-bottom: 0; }

.est-done {
    text-align: center;
    padding: 40px 16px;
}

.est-done .tick {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: #eaf1ec;
    color: var(--est-green);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.2rem;
    margin: 0 auto 18px;
}

/* ---------- desktop ---------- */

@media (min-width: 820px) {
    .est-sheet {
        left: 50%;
        right: auto;
        transform: translate(-50%, 102%);
        width: 460px;
        border-radius: 20px 20px 0 0;
    }

    .est-sheet.open { transform: translate(-50%, 0); }

    .est-actions { grid-auto-columns: minmax(0, 200px); justify-content: center; }
    .est-bar { padding-bottom: 16px; }
    .est-continue { max-width: 620px; margin: 0 auto; }
}
