@import url('https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,400;0,700;1,400;1,700&display=swap');

@font-face {
    font-family: 'CalibriWeb';
    src: url('fonts/calibri.ttf') format('truetype');
    font-weight: 400;
    font-style: normal;
}
@font-face {
    font-family: 'CalibriWeb';
    src: url('fonts/calibrib.ttf') format('truetype');
    font-weight: 700;
    font-style: normal;
}
@font-face {
    font-family: 'CalibriWeb';
    src: url('fonts/calibrii.ttf') format('truetype');
    font-weight: 400;
    font-style: italic;
}
@font-face {
    font-family: 'CalibriWeb';
    src: url('fonts/calibriz.ttf') format('truetype');
    font-weight: 700;
    font-style: italic;
}

:root {
    --ink: #18231f;
    --muted: #68736d;
    --line: #dfe6e1;
    --paper: #fff;
    --bg: #f2f5f2;
    --brand: #164f3d;
    --brand2: #28765d;
    --lime: #dff268;
    --danger: #b43e43;
    --shadow: 0 18px 50px #17382b14
}

* {
    box-sizing: border-box
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 14px/1.45 Inter, Segoe UI, Arial, sans-serif
}

.app-shell {
    display: grid;
    grid-template-columns: 245px 1fr;
    min-height: 100vh
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    background: #102c24;
    color: #fff;
    padding: 28px 18px;
    display: flex;
    flex-direction: column
}

.brand {
    padding: 0 8px 35px
}

.brand-logo {
    display: block;
    width: 78%;
    margin: 0 auto;
    border-radius: 8px;
    transition: transform .2s, opacity .2s
}

.brand-logo:hover {
    transform: scale(1.03);
    opacity: .92
}

.brand-logo:focus-visible {
    outline: 3px solid var(--lime);
    outline-offset: 4px
}

.brand-logo img {
    display: block;
    width: 100%;
    height: auto;
    object-fit: contain
}

.sidebar nav {
    display: grid;
    gap: 7px
}

.nav {
    border: 0;
    background: transparent;
    color: #aac0b7;
    text-align: left;
    padding: 14px;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 650
}

.nav:hover,
.nav.active {
    background: #ffffff12;
    color: #fff
}

.sidebar footer {
    margin-top: auto;
    color: #91aa9f;
    font-size: 12px;
    padding: 12px
}

.sidebar footer::first-letter {
    color: #77d69f
}

.main {
    padding: 0 38px 60px;
    min-width: 0
}

.main>header {
    height: 112px;
    display: flex;
    justify-content: space-between;
    align-items: center
}

.main header small,
.sectionHead small {
    color: var(--brand2);
    font-weight: 800;
    letter-spacing: .12em
}

.main h1 {
    margin: 3px 0 0;
    font-size: 29px
}

.button {
    display: inline-block;
    border: 1px solid var(--brand);
    border-radius: 9px;
    background: var(--brand);
    color: #fff;
    padding: 10px 16px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none
}

.button:hover {
    filter: brightness(1.08);
    transform: translateY(-1px)
}

.button.pale {
    background: #fff;
    color: var(--ink);
    border-color: var(--line)
}

.button.danger {
    background: #fff;
    color: var(--danger);
    border-color: #efc7ca
}

.view {
    display: none
}

.view.active {
    display: block
}

.hero {
    background: linear-gradient(115deg, #174a39, #246d54);
    color: #fff;
    border-radius: 18px;
    padding: 28px 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow)
}

.hero small {
    color: #add1c2;
    font-weight: 800;
    letter-spacing: .1em
}

.hero input {
    display: block;
    width: min(550px, 60vw);
    border: 0;
    border-bottom: 1px solid #ffffff55;
    background: transparent;
    color: #fff;
    font-size: 27px;
    font-weight: 750;
    padding: 5px 0;
    outline: 0
}

.stats {
    text-align: right
}

.stats b {
    display: block;
    font-size: 34px
}

.stats span {
    color: #b7d3c7
}

.stats i {
    font-style: normal
}

.info-box {
    background: #e9f5ff;
    border-left: 4px solid #1683f8;
    padding: 14px 18px;
    margin-bottom: 24px;
    border-radius: 6px;
    font-size: 14.5px;
    line-height: 1.55;
    color: #0b3d75
}

.info-box ul {
    margin: 8px 0 0 0;
    padding-left: 24px
}

.info-box li {
    margin-bottom: 4px
}

.info-box.warning-box {
    background: #fff6e8;
    border-left-color: #ff9800;
    color: #b05c00;
    margin: 24px 0 0
}

.panel {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: 0 7px 25px #17382b09
}

.picker {
    margin: 18px 0;
    padding: 18px 22px;
    display: flex;
    align-items: center;
    justify-content: space-between
}

.picker label {
    font-weight: 750;
    margin-right: 15px
}

.picker select {
    min-width: 330px
}

.picker p {
    display: inline;
    margin-left: 14px;
    color: var(--muted);
    font-size: 12px
}

select,
input,
textarea {
    border: 1px solid #cfd9d3;
    border-radius: 7px;
    padding: 9px 10px;
    background: #fff;
    color: var(--ink);
    font: inherit
}

.panelHead,
.sectionHead {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px
}

.panelHead {
    padding: 20px 22px
}

.panelHead h2,
.sectionHead h2 {
    margin: 0;
    font-size: 21px
}

.panelHead p,
.sectionHead p {
    margin: 4px 0;
    color: var(--muted)
}

.tableWrap {
    overflow: auto;
    border-block: 1px solid var(--line)
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 1050px
}

th {
    background: #f5f7f5;
    color: #66716b;
    text-align: left;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .04em
}

th,
td {
    padding: 9px;
    border-bottom: 1px solid #e5ebe7
}

td input {
    width: 100%;
    min-width: 100px;
    border-color: transparent;
    background: transparent;
    padding: 7px
}

td input:focus {
    border-color: #4c8d73;
    background: #fff;
    outline: 3px solid #dceee6
}

.icon {
    border: 0;
    background: transparent;
    color: #9a4b50;
    cursor: pointer;
    font-size: 18px
}

.tableFoot {
    padding: 15px 22px;
    display: flex;
    justify-content: space-between;
    align-items: center
}

.warning {
    padding: 12px 16px;
    margin-bottom: 12px;
    border-radius: 10px;
    background: #fff2d9;
    color: #714c08;
    border: 1px solid #ecd49e
}

.sectionHead {
    margin-bottom: 20px
}

.templateGrid {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 18px
}

.template-toolbar {
    position: sticky;
    top: 0;
    z-index: 5;
    padding: 12px 0;
    background: var(--bg)
}

.templateList {
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: calc(100vh - 190px);
    overflow-y: auto;
    align-self: start;
    position: sticky;
    top: 120px
}

.template-card {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #f8faf8;
    color: var(--ink);
    padding: 12px;
    text-align: left;
    font: inherit;
    font-weight: 700;
    line-height: 1.35;
    cursor: pointer;
    overflow-wrap: anywhere;
    white-space: normal;
    flex: 0 0 auto
}

.template-card:hover {
    border-color: #7cae99;
    background: #f0f7f3
}

.template-card.active {
    border-color: var(--brand2);
    background: #e6f3ed;
    box-shadow: inset 3px 0 var(--brand2)
}

.formGrid {
    padding: 22px;
    display: grid;
    grid-template-columns: repeat(2, minmax(220px, 1fr));
    gap: 15px
}

.field.full {
    grid-column: 1/-1
}

.field label {
    display: block;
    font-size: 12px;
    font-weight: 750;
    margin-bottom: 5px
}

.field input,
.field textarea {
    width: 100%
}

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

.saveBar {
    position: sticky;
    bottom: 0;
    background: #f8faf8;
    border-top: 1px solid var(--line);
    padding: 13px 22px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 0 0 14px 14px;
    color: var(--muted)
}

.print-sheet {
    width: 297mm;
    height: 210mm;
    padding: 2mm 0 0 3.9mm;
    background: #fff;
    color: #000;
    display: grid;
    grid-template-columns: 138mm 4.5mm 138mm;
    font: var(--print-font, 7.5pt)/1.05 'CalibriWeb', Arial, sans-serif;
    font-weight: 400
}

.pxx-half {
    height: 190mm;
    border: 0;
    overflow: hidden
}

.pxx-left {
    grid-column: 1
}

.pxx-right {
    grid-column: 3
}

.print-sheet b {
    color: #001eff;
    font-weight: 400
}

.print-sheet i {
    font-style: italic
}

.left-top {
    height: 18mm
}

.doc-no {
    text-align: center;
    height: 9mm;
    padding-top: 2mm
}

.maker {
    min-height: 8mm;
    padding: 1.3mm 2mm
}

.commit {
    height: 30mm;
    margin: 0;
    padding: 2mm;
    text-align: justify
}

.left-table {
    border-top: 1px solid #777
}

.pxx-row {
    min-height: 5.2mm;
    border-bottom: 1px solid #777;
    display: grid;
    grid-template-columns: 44% 31% 25%;
    align-items: center;
    padding: 0 .8mm;
    position: relative
}

.pxx-row:not(.last)::after {
    content: "";
    position: absolute;
    left: 44%;
    top: 0;
    bottom: 0;
    border-left: 1px solid #777
}

.pxx-row>span {
    grid-column: 1
}

.pxx-row>b {
    grid-column: 2;
    padding-left: 1mm
}

/* ponytail: spans cols 2-3 when row lacks <small>; add explicit column classes if 3+ cell layouts vary */
.pxx-row:not(:has(small))>b {
    grid-column: 2 / -1
}

.pxx-row>small {
    grid-column: 3;
    font-size: inherit
}

.pxx-row:nth-child(11) {
    padding-top: .7mm;
    padding-bottom: .7mm
}

.pxx-row.last {
    min-height: 10mm;
    display: block;
    padding-top: 1mm
}

.sign {
    display: grid;
    grid-template-columns: 1fr 1fr;
    min-height: 36mm;
    padding: 4mm 2mm;
    text-align: center
}

.sign>div:first-child {
    text-align: left
}

.sign>div:first-child b {
    color: #000
}

.sign b,
.sign strong,
.sign i {
    display: block
}

.sign>div:last-child>b {
    display: inline
}

.sign strong {
    margin-top: 2mm
}

.specs {
    height: 100%
}

.spec-row {
    min-height: 4.65mm;
    border-bottom: 1px solid #777;
    display: grid;
    grid-template-columns: 70% 25% 5%;
    align-items: center;
    position: relative
}

.spec-row::after {
    content: "";
    position: absolute;
    left: 70%;
    top: 0;
    bottom: 0;
    border-left: 1px solid #777
}

.motor-grid~.spec-row {
    grid-template-columns: 50% 45% 5%
}

.spec-row.wide-unit {
    grid-template-columns: 70% 22% 8%
}

.spec-row.wide-unit::after {
    left: 70%
}

.motor-grid~.spec-row::after {
    left: 50%
}

.spec-row>* {
    padding: .75mm;
    border-right: 0;
    align-self: center
}

.spec-row>b {
    padding-left: 1mm;
    text-align: left;
    text-indent: 0;
    overflow-wrap: anywhere
}

.spec-row>span {
    border-right: 0
}

.spec-row em {
    border: 0;
    text-align: right;
    font-style: normal;
    color: #000;
    justify-self: stretch
}

.motor-grid {
    display: grid;
    grid-template-columns: 1fr 1fr
}

.motor-cell {
    min-height: 9.2mm;
    border-bottom: 1px solid #777;
    display: grid;
    grid-template-columns: 58% 34% 8%;
    align-items: center;
    position: relative
}

.motor-cell::after {
    content: "";
    position: absolute;
    left: 58%;
    top: 0;
    bottom: 0;
    border-left: 1px solid #777
}

.motor-cell:nth-child(odd)::before {
    content: "";
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    border-right: 1px solid #777
}

.motor-cell>* {
    padding: .75mm;
    border-right: 0;
    align-self: center
}

.motor-cell>b {
    padding-left: 1mm
}

.motor-cell>span {
    border-right: 0
}

.motor-cell em {
    border: 0;
    text-align: right;
    font-style: normal;
    justify-self: stretch
}

.spec-note,
.first-page-note {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: start;
    column-gap: 4mm
}

.spec-note {
    min-height: 11mm;
    padding: 1mm
}

.spec-note b,
.first-page-note b {
    margin: 0;
    white-space: pre-line
}

.print-settings {
    margin-bottom: 22px;
    padding: 14px 16px;
    display: grid;
    grid-template-columns: minmax(150px, 1.2fr) repeat(3, minmax(110px, .65fr)) minmax(150px, .8fr) auto auto;
    align-items: center;
    gap: 12px
}

.print-settings>div strong,
.print-settings>div small {
    display: block
}

.print-settings>div small {
    color: var(--muted);
    margin-top: 3px
}

.print-settings label {
    font-size: 12px;
    font-weight: 750
}

.print-settings label span {
    color: var(--muted);
    font-weight: 400
}

.print-settings label input[type=number],
.print-settings label input[type=range] {
    display: block;
    width: 100%;
    margin-top: 5px
}

.print-settings label input[type=range].is-max {
    accent-color: #1683f8
}

.print-settings output {
    display: block;
    color: var(--brand2);
    font-weight: 800;
    text-align: center
}

.print-settings .safe-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0;
    white-space: nowrap
}

.print-settings .safe-toggle input {
    margin: 0
}

.screenPreview {
    display: grid;
    gap: 24px;
    justify-content: center
}

.screenPreview .print-sheet {
    box-shadow: 0 12px 40px #152d2533;
    position: relative
}

.screenPreview .print-sheet>.pxx-half {
    transform: translate(var(--print-left), var(--print-top)) scale(var(--print-scale));
    transform-origin: top left
}

.screenPreview.show-safe .print-sheet::after {
    content: "VÙNG IN AN TOÀN";
    position: absolute;
    inset: 4mm;
    border: .35mm dashed #dc7b44;
    color: #b45b2a;
    font: 700 8pt/1 Inter, Segoe UI, sans-serif;
    padding: 2mm;
    pointer-events: none
}

.preview-set {
    display: block;
    transform: scale(var(--preview-zoom, 1));
    transform-origin: top center;
    margin-bottom: calc(-190mm * (1 - var(--preview-zoom, 1)))
}

#toast {
    position: fixed;
    right: 24px;
    bottom: 24px;
    background: #112d24;
    color: #fff;
    padding: 12px 18px;
    border-radius: 10px;
    opacity: 0;
    transform: translateY(10px);
    transition: .2s;
    z-index: 20
}

#toast.show {
    opacity: 1;
    transform: none
}

@media(max-width:900px) {
    .app-shell {
        grid-template-columns: 1fr
    }

    .sidebar {
        position: static;
        height: auto;
        padding: 15px
    }

    .brand {
        padding-bottom: 14px
    }

    .sidebar nav {
        grid-template-columns: repeat(3, 1fr)
    }

    .sidebar footer {
        display: none
    }

    .main {
        padding: 0 15px 40px
    }

    .main>header {
        height: 90px
    }

    .hero {
        align-items: flex-start
    }

    .picker {
        align-items: flex-start;
        gap: 12px
    }

    .picker p {
        display: block;
        margin: 6px 0
    }

    .templateGrid {
        grid-template-columns: 1fr
    }

    .templateList {
        position: static;
        max-height: 220px
    }

    .formGrid {
        grid-template-columns: 1fr
    }

    .print-settings {
        grid-template-columns: repeat(2, 1fr)
    }

    .preview-set {
        transform: scale(.32);
        margin-bottom: -140mm
    }
}

@page {
    size: A4 landscape;
    margin: 0
}

@media print {

    .app-shell,
    #toast {
        display: none !important
    }

    html,
    body {
        width: 297mm;
        height: auto;
        min-height: 0;
        background: #fff
    }

    .print-sheet {
        display: grid;
        break-after: page;
        page-break-after: always
    }

    .print-sheet>.pxx-half {
        transform: translate(var(--print-left), var(--print-top)) scale(var(--print-scale));
        transform-origin: top left
    }

    .print-sheet:last-child {
        break-after: auto;
        page-break-after: auto
    }

    #printRoot {
        display: block
    }
}

@media screen {
    #printRoot {
        display: none
    }
}