:root {
    color-scheme: light;
    --ink: #182c42;
    --muted: #4c6279;
    --line: #d8e2ec;
    --surface: #fff;
    --ground: #f2f6fa;
    --primary: #165cc6;
    --primary-dark: #0e49a6;
    --soft: #eaf2fd;
    --error: #9f2a21;
    font: 16px/1.5 system-ui, sans-serif;
    color: var(--ink);
    background: var(--ground);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body { margin: 0; }
a { color: var(--primary-dark); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

:focus-visible {
    outline: 3px solid #2065d2;
    outline-offset: 3px;
}

.skip {
    position: fixed;
    inset: 8px auto auto 8px;
    z-index: 2;
    transform: translateY(-150%);
    padding: 8px 12px;
    background: var(--surface);
}

.skip:focus { transform: none; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(1.8rem, 4vw, 2.4rem); line-height: 1.2; }
h2 { font-size: 1.17rem; line-height: 1.3; }
.muted { color: var(--muted); font-size: .9rem; }

.shell { width: min(1280px, calc(100% - 48px)); margin-inline: auto; }
.site-header { background: var(--surface); border-bottom: 1px solid var(--line); }

.nav {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    min-height: 62px;
    gap: .65rem clamp(.8rem, 3vw, 1.8rem);
}

.nav form { margin-inline-start: auto; }
.brand { color: var(--ink); font-weight: 750; font-size: 1.1rem; text-decoration: none; }
.nav-link { color: var(--muted); text-decoration: none; }
.nav-link:hover { text-decoration: underline; }
.page { padding-block: 28px 36px; }

.page-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 14px;
    margin-bottom: 20px;
}

.card {
    min-width: 0;
    padding: 21px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
}

.button {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    padding: .55rem .95rem;
    border: 1px solid transparent;
    border-radius: 7px;
    font-weight: 650;
    text-decoration: none;
}

.primary { background: var(--primary); color: #fff; }
.primary:hover { background: var(--primary-dark); }
.secondary { color: var(--primary-dark); background: var(--soft); border-color: #b9d1f1; }
.secondary:hover { background: #dceaff; }

.text-button {
    padding: .35rem 0;
    border: 0;
    background: none;
    color: var(--primary-dark);
    text-decoration: underline;
    text-underline-offset: 2px;
}
.text-button:hover { color: var(--ink); }

.notice {
    margin-bottom: 16px;
    padding: 12px 15px;
    border: 1px solid #bed3e5;
    border-radius: 8px;
    background: var(--soft);
}
.notice-error { background: #fff2ef; border-color: #efbdb6; color: var(--error); }
.errorlist { margin: .25rem 0 0; padding: 0; list-style: none; }
.notice .errorlist { margin-bottom: .5rem; }

.login { max-width: 430px; margin: clamp(12px, 6vw, 72px) auto 0; }
.login h1 { margin-bottom: 24px; }
.login .field { margin: 0 0 17px; }
.login .errorlist { color: var(--error); }

.estimate-list { padding-block: 0; }
.estimate-list > p { padding-block: 20px; color: var(--muted); }

.estimate-link {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    padding: 16px 0;
    text-decoration: none;
}
.estimate-link + .estimate-link { border-top: 1px solid var(--line); }
.estimate-link:hover strong { text-decoration: underline; }
.estimate-details { display: grid; min-width: 0; overflow-wrap: anywhere; }
.estimate-details span, time { color: var(--muted); font-size: .9rem; }
time { flex-shrink: 0; }

.editor {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(250px, 310px);
    grid-template-areas: "questions summary" "lines summary";
    gap: 18px;
    align-items: start;
}
.questionnaire { grid-area: questions; }
.line-editor { grid-area: lines; }
.questionnaire, .line-editor { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; }

.fields {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px 18px;
    margin-top: 14px;
}
.field { min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field > label { display: block; margin-bottom: 4px; font-size: .925rem; font-weight: 570; }

input:not([type=checkbox], [type=radio], [type=hidden]), select, textarea {
    display: block;
    width: 100%;
    min-height: 42px;
    padding: .42rem .57rem;
    border: 1px solid #a8bcd0;
    border-radius: 6px;
    background: var(--surface);
}
textarea { resize: vertical; }
input::placeholder { color: #51677d; opacity: 1; }
input[aria-invalid="true"], textarea[aria-invalid="true"], select[aria-invalid="true"] {
    border-color: #b4483d;
}
.field-errors { color: var(--error); font-size: .87rem; overflow-wrap: anywhere; }
.field-errors p { margin-top: .25rem; }

.choice { margin: 0; padding: 0; min-width: 0; border: none; }
.choice legend { padding: 0; font-weight: 600; }
.choice legend + div { display: flex; flex-wrap: wrap; gap: 2px 14px; margin-top: .15rem; }
.choice label { display: flex; align-items: center; gap: 7px; min-height: 36px; cursor: pointer; }
.choice input { width: 18px; height: 18px; margin: 0; accent-color: var(--primary); flex-shrink: 0; }

.summary { grid-area: summary; position: sticky; top: 16px; background: #fbfdff; }
.summary h2 { margin-bottom: .65rem; }
.calc-status {
    display: inline-block;
    padding: .25rem .5rem;
    border-radius: 5px;
    background: var(--soft);
    color: #214877;
    font-size: .86rem;
    font-weight: 600;
}
.summary dl { margin: 14px 0 0; }
.summary dl > div {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 10px;
    padding-block: 8px;
    border-top: 1px solid var(--line);
    font-size: .9rem;
}
.summary dd { flex: 0 0 auto; max-width: 58%; margin: 0; text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.summary .grand { font-weight: 700; font-size: 1.16rem; padding-bottom: 0; }

.drilling-lines { margin-top: 10px; }
.drilling-line {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: baseline;
    gap: 7px 16px;
    padding: 11px 0;
    border-bottom: 1px solid var(--line);
}
.drilling-line s { margin-right: .45rem; color: var(--muted); }
.drilling-line > strong { text-align: right; }

.line-section > p { margin-top: 8px; }
table { width: 100%; border-collapse: collapse; table-layout: fixed; margin-top: 10px; }
thead th { color: var(--muted); font-size: .84rem; font-weight: 630; }
th, td { text-align: left; vertical-align: top; padding: .52rem .3rem; border-bottom: 1px solid var(--line); }
thead th:first-child { width: 49%; }
tbody th { font-weight: 550; }
tbody th small { display: inline-block; margin-left: .2rem; font-weight: 400; color: var(--muted); }
.reset { display: block; font-size: .85rem; }
td input { font-variant-numeric: tabular-nums; }
.line-total { padding-top: .95rem; font-size: .91rem; overflow-wrap: anywhere; }
.small-label { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.line-section thead th:first-child { width: 43%; }
.line-actions { width: 44px; text-align: right; }
.exclude-line {
    display: inline-flex; align-items: center; justify-content: center;
    width: 36px; height: 42px; border: 0; border-radius: 6px;
    background: transparent; color: #bf3025;
}
.exclude-line:hover { background: #fff0ee; }
.restore-line { display: block; font-size: .85rem; }
.excluded .line-name { color: var(--muted); text-decoration: line-through; }
.excluded input:not([type=hidden]) { color: var(--muted); background: var(--ground); }

.custom-row { padding-block: 12px; border-bottom: 1px solid var(--line); }
.custom-fields {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1.5fr) repeat(3, minmax(0, .75fr));
    gap: 10px;
}
.custom-actions { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; gap: 10px; }
#add-line { margin-top: 14px; }

.save-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 12px;
    position: sticky;
    bottom: 0;
    margin-top: 18px;
    padding: 11px 15px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 9px;
    box-shadow: 0 -3px 14px #24496f14;
}
#save-state { font-size: .93rem; font-weight: 650; }
.save-total { display: none; }
html { scroll-padding-bottom: 125px; }

@media (max-width: 900px) {
    .editor { display: flex; flex-direction: column; }
    .editor > * { width: 100%; }
    .summary { position: static; }
    .save-total { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 9px; }
    .save-total strong { overflow-wrap: anywhere; }
}

@media (max-width: 600px) {
    .shell { width: calc(100% - 24px); }
    .nav { min-height: 55px; font-size: .9rem; }
    .page { padding-top: 19px; }
    .card { padding: 14px; }
    .fields { grid-template-columns: minmax(0, 1fr); }
    .estimate-link { flex-direction: column; gap: 4px; }
    .drilling-line { grid-template-columns: minmax(0, 1fr) auto; }
    .drilling-line > span:first-child { grid-column: 1 / -1; }
    table, tbody { display: block; }
    thead {
        position: absolute;
        width: 1px;
        height: 1px;
        margin: -1px;
        overflow: hidden;
        clip-path: inset(50%);
    }
    tr {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, .88fr);
        gap: .35rem .52rem;
        padding: .7rem 0;
        border-bottom: 1px solid var(--line);
    }
    th, td { border: 0; padding: 0; }
    tbody th { grid-column: 1 / -1; overflow-wrap: anywhere; }
    .line-section tr { position: relative; }
    .line-section tbody th { padding-right: 44px; }
    .line-section .line-actions { position: absolute; top: .7rem; right: 0; }
    .small-label { display: block; color: var(--muted); font-size: .77rem; }
    .line-total { padding-top: 0; }
    .line-total strong { display: block; padding-top: .6rem; }
    .custom-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .custom-fields > :first-child { grid-column: 1 / -1; }
}

@media (pointer: coarse) {
    .exclude-line { width: 44px; height: 44px; }
    .restore-line { min-height: 44px; }
}

@media (max-width: 420px) {
    .save-bar > button { width: 100%; }
}

.google-settings { max-width: 720px; margin-bottom: 16px; overflow-wrap: anywhere; }
.google-settings p, .google-settings form { margin-top: .7rem; }
.google-settings [role=status]:empty { display: none; }
.google-settings button:disabled { cursor: wait; opacity: .75; }
