@font-face { font-family: "Google Sans"; src: url("google-sans.woff2") format("woff2"); font-weight: 400 700; font-display: swap; }
@font-face {
    font-family: "TOY Thai";
    src: url("NotoSansThai-Regular.ttf") format("truetype");
    font-weight: 400 500;
    font-display: swap;
}
@font-face {
    font-family: "TOY Thai";
    src: url("NotoSansThai-Bold.ttf") format("truetype");
    font-weight: 600 900;
    font-display: swap;
}
:root {
    --ink: #101e33;
    --muted: #536278;
    --surface: #fff;
    --soft: #f6f7fb;
    --line: #e1e6ee;
    --nav: #111d30;
    --accent: #b84013;
    --store-color: #c64912;
    --danger: #a52a31;
    --radius: 16px;
    color: var(--ink);
    background: var(--soft);
    font-family: "Google Sans", "TOY Thai", "Noto Sans Thai", system-ui, sans-serif;
    font-size: 15px;
    line-height: 1.55;
    font-variant-numeric: tabular-nums;
}
* { box-sizing: border-box; }
body { margin: 0; }
h1, h2, p { margin: 0 0 .65rem; }
h1 { font-size: clamp(1.65rem, 3vw, 2.45rem); line-height: 1.2; letter-spacing: -.035em; }
h2 { font-size: 1.16rem; line-height: 1.4; }
a { color: #194875; text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }
button, .button {
    border: 1px solid transparent;
    border-radius: 9px;
    padding: .58rem .88rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    cursor: pointer;
    color: var(--ink);
    background: transparent;
    font-weight: 700;
    line-height: 1.3;
    text-decoration: none;
    text-align: center;
}
.button:hover { text-decoration: none; }
button:hover, .button:hover { filter: brightness(.94); }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible {
    outline: 3px solid #1763ac;
    outline-offset: 2px;
}
.primary { background: color-mix(in srgb, var(--store-color) 70%, #701600); color: #fff; }
.secondary { color: #233550; background: #fff; border-color: #d2dae7; }
.ghost { color: #225078; background: #eef4f9; }
.danger { color: var(--danger); }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.1rem 0; }
label { display: flex; flex-direction: column; gap: .24rem; min-width: 0; font-size: .91rem; font-weight: 700; }
input:not([type=hidden]):not([type=checkbox]), select, textarea {
    display: block;
    border: 1px solid #c9d3e2;
    border-radius: 9px;
    padding: .54rem .66rem;
    min-height: 42px;
    width: 100%;
    max-width: 100%;
    color: var(--ink);
    background: #fff;
    font-weight: 400;
}
input[type=color] { min-width: 90px; }
textarea { resize: vertical; }
.check { flex-direction: row; align-items: center; gap: .52rem; min-height: 42px; padding-top: .5rem; }
.check input { accent-color: var(--accent); width: 18px; height: 18px; }
.auth {
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    background: radial-gradient(ellipse at 12% 25%, #ffe2cb, transparent 40%), linear-gradient(130deg,#f9f0eb,#eaf0f9);
}
.auth-card { width: min(100%,620px); padding: clamp(1.2rem,5vw,2.45rem); border: 1px solid var(--line); border-radius: 23px; background: #fff; box-shadow: 0 25px 75px #1729451a; }
.auth-card > .brand { color: var(--ink); margin-bottom: 1.7rem; }
.auth-card > form > label { margin-bottom: .95rem; }
.auth-card > form > button { margin-top: .35rem; }
.checks { display: grid; grid-template-columns: repeat(auto-fit,minmax(180px,1fr)); gap: .4rem; padding: 0; list-style: none; }
.checks li { background: var(--soft); padding: .42rem .6rem; border-radius: 8px; }
.app { min-height: 100dvh; display: grid; grid-template-columns: 228px minmax(0,1fr); }
.sidebar {
    background: linear-gradient(160deg,#18283f,#0e1727 72%);
    padding: 1.1rem .85rem;
    min-height: 100dvh;
    position: sticky;
    top: 0;
    align-self: start;
    height: 100dvh;
    overflow-y: auto;
}
.brand {
    display: flex;
    align-items: center;
    gap: .7rem;
    font-weight: 800;
    font-size: .96rem;
    color: #fff;
    line-height: 1.3;
}
.sidebar .brand { padding: .35rem .3rem 1.35rem; }
.brand-mark {
    background: linear-gradient(145deg,#dd612c,#a73b16);
    border-radius: 11px;
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    color: #fff;
    display: grid;
    place-items: center;
    font-size: 1.18rem;
}
.sidebar nav { display: grid; gap: .23rem; }
.sidebar nav a {
    display: flex;
    gap: .7rem;
    align-items: center;
    padding: .61rem .74rem;
    color: #d7e1ee;
    border-radius: 9px;
    font-weight: 700;
}
.sidebar nav a span { width: 1.1rem; text-align: center; }
.sidebar nav a:hover { background: #ffffff16; text-decoration: none; }
.sidebar a[aria-current=page] { background: #ffffff20; color: #fff; box-shadow: inset 3px 0 var(--store-color); }
.nav-label { color: #9babbd; font-size: .76rem; padding: 1.1rem .72rem .15rem; }
.workspace { min-width: 0; }
.topbar {
    min-height: 68px;
    background: #fff;
    border-bottom: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .7rem;
    padding: .6rem clamp(.8rem,3vw,2rem);
}
.user-menu, .store-switch { display: flex; align-items: end; gap: .6rem; }
.user-menu { align-items: center; margin-left: auto; white-space: nowrap; }
.store-switch label { min-width: min(220px,28vw); max-width: 280px; }
.store-switch select { padding-top: .28rem; padding-bottom: .28rem; min-height: 34px; }
.store-switch button { min-height: 34px; white-space: nowrap; padding-top: .42rem; padding-bottom: .42rem; }
.store-switch label span { color: var(--muted); font-size: .75rem; }
.menu-toggle { display: none; }
.main { margin: 0 auto; max-width: 1640px; padding: clamp(.8rem,2.7vw,2rem); }
.page-heading { display: flex; justify-content: space-between; align-items: end; gap: 1rem; margin: .25rem 0 1.3rem; }
.page-heading h1 { margin: 0; }
.context { color: var(--muted); font-size: .83rem; font-weight: 700; margin-bottom: .35rem; }
.card, .metric {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 3px 10px #24334f06;
    padding: clamp(.85rem,1.75vw,1.35rem);
    min-width: 0;
}
.card, .paper { margin-bottom: 1rem; }
.card > h2 { margin-bottom: .8rem; }
.metrics { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: .75rem; margin-bottom: 1rem; }
.metric { display: grid; gap: .32rem; border-top: 3px solid color-mix(in srgb,var(--store-color),white 45%); }
.metric strong { overflow-wrap: anywhere; font-size: clamp(1.25rem,2.2vw,1.8rem); }
.metric > span { font-weight: 700; }
.metric small, .muted { color: var(--muted); }
.dashboard-grid { display: grid; grid-template-columns: minmax(0,1.45fr) minmax(0,1fr); gap: .8rem; }
.bars { display: grid; gap: .75rem; padding: 0; margin: .5rem 0; list-style: none; }
.bars li { display: grid; gap: .6rem; grid-template-columns: minmax(65px,.65fr) minmax(45px,2fr) auto; align-items: center; }
.track { background: #edf0f5; border-radius: 12px; height: 11px; overflow: hidden; }
.track > div { background: var(--store-color); height: 100%; border-radius: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: .8rem; margin: .65rem 0 1rem; }
.wide { grid-column: 1/-1; }
.filters, .actions, .pager { display: flex; gap: .5rem; flex-wrap: wrap; align-items: end; margin: .75rem 0; }
.filters > label { min-width: min(165px,100%); }
.actions > span { align-self: center; }
.pager { justify-content: flex-end; align-items: center; }
.table-wrap { max-width: 100%; overflow-x: auto; }
table { border-collapse: collapse; width: 100%; text-align: left; font-size: .92rem; }
th { color: #425570; font-weight: 700; background: #f4f6fa; }
th, td { padding: .69rem .64rem; border-bottom: 1px solid var(--line); vertical-align: top; }
td { overflow-wrap: anywhere; }
td .button { padding: .26rem .57rem; min-height: 31px; white-space: nowrap; }
td form { min-width: 95px; }
.empty { color: var(--muted); padding: 1rem; text-align: center; }
.status { display: inline-block; border-radius: 25px; background: #eaf0f8; color: #283e5a; font-size: .82rem; padding: .19rem .55rem; white-space: nowrap; }
.status.ok, .alert.good { color: #17603f; background: #e7f6ed; }
.status.dead, .alert.bad { color: #8b2730; background: #ffecee; }
.alert { border-radius: 10px; padding: .7rem .9rem; margin: .7rem 0; }
.line { border: 1px solid var(--line); border-radius: 11px; background: #fafbfe; padding: .75rem; margin: 0 0 .6rem; }
.line-header { display: flex; justify-content: space-between; gap: .5rem; align-items: center; }
.line-header .actions { margin: 0; }
.line-header button { padding: .22rem .55rem; min-height: 30px; }
.line-grid { grid-template-columns: minmax(120px,1.65fr) minmax(110px,1.45fr) repeat(4,minmax(65px,.65fr)); margin-bottom: 0; }
.line-grid textarea { min-height: 58px; }
.after-lines { margin-top: 1.1rem; }
.calc-total { padding: .35rem .75rem; border: 1px solid var(--line); border-radius: 9px; display: grid; }
.calc-total output { font-weight: 800; font-size: 1.1rem; }
.multiline { white-space: pre-wrap; overflow-wrap: anywhere; }
.print-toolbar { display: flex; justify-content: center; gap: .75rem; padding: 1.1rem; }
.paper {
    width: min(100%,210mm);
    padding: clamp(.8rem,3vw,13mm);
    margin-right: auto;
    margin-left: auto;
    color: #172334;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 9px;
}
.paper-head {
    display: grid;
    grid-template-columns: 1.35fr minmax(160px,1fr);
    gap: 1rem;
    padding-bottom: .9rem;
    border-top: 5px solid var(--store-color);
    border-bottom: 1px solid var(--line);
    padding-top: .8rem;
}
.paper-brand { font-size: 1.45rem; font-weight: 800; }
.paper-id { text-align: right; }
.paper-id h2 { font-size: 1.43rem; margin: 0; }
.buyer { display: grid; padding: .75rem 0 1rem; }
.paper-summary { margin-top: .95rem; display: grid; grid-template-columns: minmax(0,1fr) minmax(215px,.8fr); gap: 1rem; }
.totals { margin: 0; }
.totals > div { display: flex; justify-content: space-between; gap: .5rem; padding: .28rem 0; }
.totals dd { margin: 0; text-align: right; }
.grand { border-top: 1px solid var(--line); font-weight: 800; }
.amount-words { padding: .38rem .6rem; background: #f2f4f8; font-weight: 700; }
.signatures { display: grid; grid-template-columns: 1fr 1fr; gap: 4rem; text-align: center; margin-top: 2rem; }
.signatures div { border-top: 1px solid #a3adbe; padding-top: .3rem; }
details summary { cursor: pointer; }
@media(max-width: 1060px) {
    .app { grid-template-columns: 192px minmax(0,1fr); }
    .dashboard-grid { grid-template-columns: 1fr; gap: 0; }
    .line-grid { grid-template-columns: repeat(3,minmax(0,1fr)); }
}
@media(max-width: 760px) {
    .app { display: block; }
    .sidebar { display: none; position: static; height: auto; min-height: 0; }
    .sidebar.open { display: block; }
    .sidebar nav { grid-template-columns: repeat(2,minmax(0,1fr)); }
    .nav-label { grid-column: 1/-1; }
    .menu-toggle { display: inline-flex; }
    .topbar { flex-wrap: wrap; }
    .user-menu > span { display: none; }
    .store-switch { order: 3; width: 100%; }
    .store-switch label { flex: 1; max-width: none; }
    .metrics { grid-template-columns: repeat(2,minmax(0,1fr)); }
    .paper { width: 100%; }
    .main table.dense { min-width: 530px; }
}
@media(max-width: 430px) {
    .form-grid { grid-template-columns: 1fr; }
    .line-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
    .paper-summary, .paper-head { grid-template-columns: 1fr; }
    .paper-id { text-align: left; }
    .metrics { grid-template-columns: repeat(2,minmax(0,1fr)); }
    .page-heading { align-items: start; flex-direction: column; }
}
@page { size: A4; margin: 12mm; }
@media print {
    :root, body { background: #fff; color: #111827; font-size: 10pt; }
    .print-toolbar { display: none; }
    .paper { width: 100%; padding: 0; margin: 0; border: 0; border-radius: 0; }
    .paper-head { grid-template-columns: 1.35fr 1fr; padding-top: 5mm; }
    .paper-id { text-align: right; }
    .paper-summary { grid-template-columns: 1fr 1fr; }
    .table-wrap { overflow: visible; }
    table { table-layout: fixed; font-size: 9pt; }
    th, td { padding: 2.1mm 1.5mm; }
    th:first-child { width: 10%; }
    th:nth-child(2) { width: 37%; }
    thead { display: table-header-group; }
    tr, .paper-head, .paper-summary, .signatures { break-inside: avoid; }
    * { print-color-adjust: exact; }
}
.print-logo { display: block; max-width: 155px; max-height: 52px; object-fit: contain; margin: 0 0 .45rem; }
.context { display: flex; align-items: center; gap: .5rem; }
.context-logo { max-width: 52px; max-height: 25px; object-fit: contain; }
.catalog-picker { display: grid; gap: .45rem; }
.profile { max-width: 155px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
@media(max-width: 430px) { .profile { max-width: 110px; } }
.number-settings { display: grid; grid-template-columns: repeat(auto-fit,minmax(min(260px,100%),1fr)); gap: .65rem; }
.rule { padding: .7rem; background: var(--soft); border: 1px solid var(--line); border-radius: 10px; }
.rule h3 { margin: 0; font-size: 1rem; }
