:root {
    color-scheme: light;
    --bg: #f4f6f8;
    --panel: #ffffff;
    --ink: #1d2730;
    --muted: #667481;
    --line: #d9e0e6;
    --primary: #166b8f;
    --primary-dark: #0f526e;
    --accent: #2f8b57;
    --danger: #b3261e;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 15px;
    line-height: 1.45;
}

a {
    color: inherit;
}

.shell {
    width: min(1160px, calc(100% - 32px));
    margin: 0 auto;
}

.topbar {
    background: #ffffff;
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 5;
}

.nav {
    min-height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    text-decoration: none;
    font-size: 18px;
}

.brand img {
    width: 116px;
    max-height: 38px;
    object-fit: contain;
}

nav {
    display: flex;
    gap: 8px;
}

nav a,
.button,
.small-link {
    border-radius: 6px;
    text-decoration: none;
}

nav a {
    padding: 10px 12px;
    color: var(--muted);
}

nav a:hover {
    background: #eef3f6;
    color: var(--ink);
}

main.shell {
    padding: 28px 0 48px;
}

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 18px;
}

h1 {
    margin: 0;
    font-size: 28px;
    line-height: 1.2;
}

h2 {
    font-size: 18px;
    margin: 0 0 12px;
}

p {
    margin: 6px 0 0;
    color: var(--muted);
}

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
    box-shadow: 0 8px 24px rgba(20, 35, 48, 0.06);
}

.button,
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 0 14px;
    border: 1px solid var(--line);
    background: #ffffff;
    color: var(--ink);
    font: inherit;
    cursor: pointer;
}

.button:hover,
button:hover {
    background: #eef3f6;
}

.button.primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #ffffff;
}

.button.primary:hover {
    background: var(--primary-dark);
}

.actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
}

.inline-form {
    margin: 0;
}

.search {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    margin-bottom: 16px;
}

input,
select,
textarea {
    width: 100%;
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 9px 10px;
    background: #ffffff;
    color: var(--ink);
    font: inherit;
}

textarea {
    resize: vertical;
}

label {
    display: grid;
    gap: 7px;
    color: #394650;
    font-weight: 600;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.span-2,
.block {
    grid-column: 1 / -1;
}

.form-divider {
    display: flex;
    align-items: baseline;
    gap: 10px;
    border-top: 1px solid var(--line);
    padding-top: 14px;
    color: var(--ink);
}

.form-divider span {
    color: var(--muted);
    font-size: 13px;
}

.quote-form {
    display: grid;
    gap: 18px;
}

.live-totals {
    width: min(420px, 100%);
    margin-left: auto;
    display: grid;
    gap: 8px;
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fafb;
}

.live-totals div {
    display: flex;
    justify-content: space-between;
    gap: 18px;
}

.live-totals span {
    color: var(--muted);
}

.live-totals .grand {
    border-top: 1px solid var(--line);
    padding-top: 10px;
    font-size: 18px;
}

.copy-summary {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 8px 16px;
    padding: 14px;
    background: #f8fafb;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.copy-summary strong {
    color: var(--muted);
}

.company-choice-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.choice-card {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: start;
    gap: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    font-weight: 400;
}

.choice-card input,
.checkbox-row input {
    width: auto;
    min-height: auto;
    margin-top: 3px;
}

.choice-card span {
    display: grid;
    gap: 3px;
}

.choice-card small {
    color: var(--muted);
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.table-wrap {
    overflow-x: auto;
}

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

#items {
    table-layout: fixed;
    min-width: 1240px;
}

#items th:nth-child(2),
#items td:nth-child(2) {
    width: 31%;
}

#items th:nth-child(3),
#items td:nth-child(3),
#items th:nth-child(7),
#items td:nth-child(7) {
    width: 7%;
}

#items th:nth-child(4),
#items td:nth-child(4) {
    width: 8%;
}

#items th:nth-child(5),
#items td:nth-child(5) {
    width: 12%;
}

#items th:nth-child(6),
#items td:nth-child(6) {
    width: 15%;
}

#items th:first-child,
#items td:first-child,
#items th:last-child,
#items td:last-child {
    width: 44px;
    padding-left: 6px;
    padding-right: 6px;
    text-align: center;
}

th,
td {
    padding: 12px 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

th {
    color: #41505c;
    font-size: 13px;
    font-weight: 700;
    background: #f8fafb;
}

tr:last-child td {
    border-bottom: 0;
}

.small-link {
    color: var(--primary);
    font-weight: 700;
}

.link-button {
    display: inline;
    width: auto;
    min-height: 0;
    border: 0 !important;
    padding: 0 !important;
    background: transparent !important;
    box-shadow: none;
    font: inherit;
    cursor: pointer;
}

.link-button:hover {
    background: transparent !important;
    text-decoration: underline;
}

.danger-link {
    color: var(--danger);
}

.table-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.company-actions {
    align-items: center;
    flex-wrap: nowrap;
    gap: 16px;
    white-space: nowrap;
}

.customer-actions {
    align-items: center;
    gap: 12px;
}

.quote-actions {
    align-items: center;
    flex-wrap: nowrap;
    gap: 14px;
    white-space: nowrap;
}

.status {
    display: inline-flex;
    min-height: 28px;
    align-items: center;
    padding: 0 10px;
    border-radius: 999px;
    background: #e8f3ec;
    color: var(--accent);
    font-weight: 700;
    font-size: 13px;
}

.empty {
    color: var(--muted);
    text-align: center;
    padding: 32px;
}

.notice {
    margin-bottom: 16px;
    padding: 12px 14px;
    border-radius: 6px;
    border: 1px solid #cddccf;
    background: #eff8f1;
    color: #205c33;
}

.notice.error {
    border-color: #efc8c4;
    background: #fff0ef;
    color: var(--danger);
}

.login-wrap {
    min-height: calc(100vh - 140px);
    display: grid;
    place-items: center;
}

.login-panel {
    width: min(420px, 100%);
    display: grid;
    gap: 16px;
}

.login-panel h1,
.login-panel p {
    text-align: center;
}

.login-logo {
    width: 220px;
    max-width: 100%;
    justify-self: center;
}

.icon-button {
    min-width: 38px;
    padding: 0;
    font-size: 22px;
    line-height: 1;
}

.drag-handle {
    width: 32px;
    min-height: 32px;
    padding: 0;
    color: var(--muted);
    cursor: grab;
    font-size: 18px;
    line-height: 1;
    user-select: none;
    touch-action: none;
}

.drag-handle:active {
    cursor: grabbing;
}

tr.dragging {
    opacity: 0.55;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.detail-grid div {
    display: grid;
    gap: 4px;
}

.detail-grid span,
.totals span {
    color: var(--muted);
}

.items-panel {
    padding: 0;
    overflow: hidden;
}

.totals {
    width: min(380px, 100%);
    margin-left: auto;
    padding: 12px 18px 18px;
    display: grid;
    gap: 8px;
}

.totals div {
    display: flex;
    justify-content: space-between;
    gap: 18px;
}

.totals .grand {
    border-top: 1px solid var(--line);
    padding-top: 10px;
    font-size: 18px;
}

.print-page {
    background: #d8dde2;
}

.print-sheet {
    width: 210mm;
    min-height: 297mm;
    margin: 24px auto;
    background: #ffffff;
    padding: 18mm;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.16);
}

.print-actions {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 14px;
}

.print-head {
    border-bottom: 2px solid var(--ink);
    padding-bottom: 16px;
    margin-bottom: 22px;
}

.print-head-table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
}

.print-head-table td {
    border: 0;
    padding: 0;
    vertical-align: top;
}

.print-head-left {
    width: 58%;
}

.print-head-right {
    width: 42%;
    text-align: right;
}

.print-head h1 {
    font-size: 30px;
    margin-top: 18px;
}

.print-company-title {
    max-width: 360px;
    color: var(--ink);
    font-size: 24px;
    font-weight: 800;
    line-height: 1.12;
    text-transform: uppercase;
}

.company-info {
    width: 260px;
    display: grid;
    gap: 5px;
    text-align: right;
    color: var(--muted);
}

.company-info strong {
    color: var(--ink);
}

.print-side {
    display: grid;
    gap: 18px;
    justify-items: end;
}

.print-date-box {
    display: grid;
    gap: 6px;
    text-align: right;
}

.print-date-box div {
    display: grid;
    gap: 2px;
}

.print-date-box strong {
    font-size: 12px;
    color: var(--muted);
}

.print-date-box span {
    color: var(--ink);
    font-weight: 700;
}

.print-page .items-panel table {
    table-layout: fixed;
    font-size: 11px;
    line-height: 1.12;
}

.print-page .items-panel th,
.print-page .items-panel td {
    padding: 5px 6px;
    vertical-align: middle;
}

.print-page .items-panel th:first-child,
.print-page .items-panel td:first-child {
    width: 44%;
}

.print-page .items-panel th:nth-child(2),
.print-page .items-panel td:nth-child(2) {
    width: 8%;
    white-space: nowrap;
}

.print-page .items-panel th:nth-child(3),
.print-page .items-panel td:nth-child(3) {
    width: 8%;
    white-space: nowrap;
}

.print-page .items-panel th:nth-child(4),
.print-page .items-panel td:nth-child(4),
.print-page .items-panel th:nth-child(5),
.print-page .items-panel td:nth-child(5),
.print-page .items-panel th:nth-child(6),
.print-page .items-panel td:nth-child(6) {
    width: 13.33%;
    white-space: nowrap;
}

.print-items-page {
    display: block !important;
    break-before: page !important;
    page-break-before: always !important;
}

.print-page .totals {
    padding-top: 8px;
    gap: 4px;
    font-size: 12px;
}

.customer-box,
.notes,
.prepared-by {
    margin-top: 20px;
}

.customer-box {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
}

.customer-box p,
.notes p {
    color: var(--ink);
}

.customer-box h2 {
    margin-bottom: 8px;
}

.customer-box p {
    margin: 4px 0;
}

.prepared-by {
    border-top: 1px solid var(--ink);
    padding-top: 12px;
    display: grid;
    gap: 5px;
    width: min(420px, 100%);
    margin-left: auto;
    margin-top: 6px;
}

.prepared-by h2 {
    margin-bottom: 0;
}

.prepared-line {
    display: flex;
    align-items: baseline;
    gap: 22px;
    flex-wrap: wrap;
}

.prepared-by span {
    color: var(--muted);
}

@media (max-width: 760px) {
    .nav,
    .page-head {
        flex-direction: column;
        align-items: stretch;
    }

    nav,
    .actions {
        flex-wrap: wrap;
    }

    .form-grid,
    .company-choice-grid,
    .detail-grid,
    .search {
        grid-template-columns: 1fr;
    }

    .panel {
        padding: 14px;
    }
}

@media print {
    @page {
        size: A4;
        margin: 10mm 8mm;
    }

    body,
    .print-page {
        background: #ffffff;
    }

    .print-sheet {
        width: auto;
        min-height: auto;
        margin: 0;
        padding: 0;
        box-shadow: none;
    }

    .print-head {
        padding-bottom: 10px;
        margin-bottom: 12px;
    }

    .print-head-left {
        width: 58%;
    }

    .print-head-right {
        width: 42%;
        text-align: right;
    }

    .print-company-title {
        max-width: 100%;
        font-size: 18px;
        line-height: 1.12;
    }

    .print-head h1 {
        font-size: 22px;
        margin-top: 14px;
    }

    .print-date-box,
    .company-info {
        width: auto;
        text-align: right;
    }

    .print-date-box {
        gap: 4px;
    }

    .print-date-box strong,
    .company-info {
        font-size: 10px;
    }

    .print-date-box span {
        font-size: 11px;
    }

    .customer-box {
        padding: 9px 10px;
        margin-top: 12px;
    }

    .customer-box h2,
    .notes h2,
    .prepared-by h2 {
        font-size: 14px;
        margin-bottom: 8px;
    }

    .customer-box p,
    .notes p,
    .prepared-by {
        font-size: 11px;
    }

    .items-panel {
        margin-top: 8px;
        overflow: visible;
    }

    .items-panel table {
        table-layout: fixed;
        font-size: 8px;
        line-height: 1.08;
    }

    .items-panel thead {
        display: table-row-group;
    }

    .items-panel tr,
    .items-panel td,
    .items-panel th {
        break-inside: avoid;
        page-break-inside: avoid;
    }

    .items-panel th,
    .items-panel td {
        padding: 3px 4px;
        vertical-align: middle;
    }

    .items-panel th:first-child,
    .items-panel td:first-child {
        width: 44%;
    }

    .items-panel th:nth-child(2),
    .items-panel td:nth-child(2) {
        width: 8%;
        white-space: nowrap;
    }

    .items-panel th:nth-child(3),
    .items-panel td:nth-child(3) {
        width: 8%;
        white-space: nowrap;
    }

    .items-panel th:nth-child(4),
    .items-panel td:nth-child(4),
    .items-panel th:nth-child(5),
    .items-panel td:nth-child(5),
    .items-panel th:nth-child(6),
    .items-panel td:nth-child(6) {
        width: 13.33%;
        white-space: nowrap;
    }

    .totals {
        width: 270px;
        padding: 8px 10px 10px;
        gap: 5px;
        font-size: 11px;
        break-inside: avoid;
        page-break-inside: avoid;
    }

    .totals .grand {
        font-size: 13px;
        padding-top: 7px;
    }

    .notes {
        margin-top: 12px;
        break-inside: avoid;
        page-break-inside: avoid;
    }

    .prepared-by {
        width: 260px;
        padding-top: 8px;
        gap: 2px;
        margin-top: 4px;
        break-inside: avoid;
        page-break-inside: avoid;
    }

    .print-actions,
    .topbar {
        display: none;
    }

    .panel {
        box-shadow: none;
        border-color: #b9c2ca;
    }
}
