/* STPartner — ตามแบบ mockup: กระดาษอุ่น + น้ำเงินปิโตรล, IBM Plex Sans Thai, ตัวเลขใช้ Plex Mono */
:root {
  --ink: #1B2433; --ink-2: #3A4556; --muted: #556070; --line: #DEDBD2; --line-2: #ECEAE4; --field: #C9C5BA;
  --paper: #F6F5F1; --card: #FFFFFF; --pri: #0F5F7A; --pri-ink: #0A4458; --pri-soft: #E3EEF2;
  --navy: #13203A; --navy-2: #2A3A58; --navy-ink: #E8ECF3; --navy-muted: #A9B3C4;
  --ok-bg: #E4F0E6; --ok: #24562F; --warn-bg: #FBF0DC; --warn: #7A4A06; --warn-line: #E9CF9F; --err-bg: #F8E3E0; --err: #8A2A1E;
  --sans: 'IBM Plex Sans Thai', 'Noto Sans Thai', 'Sarabun', sans-serif; --mono: 'IBM Plex Mono', ui-monospace, monospace;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: var(--sans); color: var(--ink); background: var(--paper); font-size: 15px; line-height: 1.55; }
a { color: var(--pri); } a:hover { color: var(--pri-ink); }
:focus-visible { outline: 2px solid var(--pri); outline-offset: 2px; }
h1 { margin: 4px 0 0; font-size: 28px; font-weight: 600; line-height: 1.3; }
h2 { margin: 0; font-size: 18px; font-weight: 600; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* โครงหน้า: เมนูข้าง + เนื้อหา (มือถือ: เมนูซ้อนด้านบน) */
.shell { display: flex; flex-wrap: wrap; min-height: 100vh; align-items: stretch; background: var(--card); }
.shell.super { background: var(--navy); }
.side { flex: 1 1 248px; max-width: 100%; padding: 24px 16px; display: flex; flex-direction: column; gap: 24px; border-right: 1px solid var(--line); }
.shell.super .side { border-right: 0; color: var(--navy-ink); }
.main { flex: 999 1 560px; min-width: 0; background: var(--paper); padding: 32px 40px; display: flex; flex-direction: column; gap: 20px; }
@media (max-width: 700px) { .main { padding: 24px 16px; } }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; font-size: 18px; font-weight: 600; }
.brand .mark { width: 34px; height: 34px; border-radius: 9px; background: var(--pri); color: #fff; display: grid; place-items: center; font-family: var(--mono); font-size: 14px; }
.shell.super .brand .mark { background: var(--navy-ink); color: var(--navy); }
.roombox { margin: 0 8px; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.roombox b { display: block; font-size: 14px; font-weight: 600; line-height: 1.4; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav .grp { font-size: 12px; color: var(--muted); padding: 8px 12px 4px; }
.shell.super .nav .grp { color: var(--navy-muted); }
.nav a { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 10px 12px; border-radius: 10px; text-decoration: none; color: var(--ink-2); }
.nav a svg { width: 20px; height: 20px; flex: none; }
.nav a.on { background: var(--pri-soft); color: var(--pri-ink); font-weight: 600; }
.shell.super .nav a { color: #C3CBD8; }
.shell.super .nav a.on { background: var(--navy-2); color: #fff; }
.quota { margin: 0 8px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; font-size: 13px; }
.bar { height: 6px; background: var(--line-2); border-radius: 3px; margin-top: 6px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--pri); border-radius: 3px; }
.bar.hot > i { background: #B45309; }
.who { display: flex; align-items: center; gap: 10px; padding: 0 8px; margin-top: auto; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--pri-soft); color: var(--pri-ink); display: grid; place-items: center; font-weight: 600; font-size: 14px; flex: none; }
.shell.super .avatar { background: var(--navy-2); color: #fff; }
.who .n { font-size: 14px; font-weight: 600; } .who .r { font-size: 12px; color: var(--muted); }
.shell.super .who .r { color: var(--navy-muted); }
.linkbtn { background: none; border: 0; padding: 6px; font: inherit; font-size: 13px; color: var(--pri); cursor: pointer; text-decoration: underline; }
.shell.super .linkbtn { color: #C3D9E2; }

/* ส่วนประกอบ */
.head { display: flex; justify-content: space-between; align-items: flex-end; flex-wrap: wrap; gap: 16px; }
.crumb { font-size: 14px; color: var(--muted); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 22px; }
.card.flush { padding: 0; }
.card > h2 + * { margin-top: 14px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; }
.stat .k { font-size: 14px; color: var(--muted); } .stat .v { font-size: 30px; font-weight: 600; font-family: var(--mono); line-height: 1.3; }
.stat .v small { font-size: 16px; color: var(--muted); font-weight: 400; }
.stat.warn { background: var(--warn-bg); border-color: var(--warn-line); } .stat.warn .k, .stat.warn .v { color: var(--warn); }
.grid2 { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; }
.grid2 > * { flex: 1 1 420px; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.row > label { flex: 1 1 180px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px; border-radius: 10px; border: 1px solid var(--field); background: #fff; color: var(--ink); font: inherit; font-size: 15px; text-decoration: none; cursor: pointer; }
.btn:hover { border-color: var(--muted); color: var(--ink); }
.btn.pri { background: var(--pri); border-color: var(--pri); color: #fff; font-weight: 600; }
.btn.pri:hover { background: var(--pri-ink); color: #fff; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn.danger { color: var(--err); border-color: #E2B8B1; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

label.f { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 500; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  min-height: 44px; border: 1px solid var(--field); border-radius: 10px; padding: 0 12px; font: inherit; font-size: 15px; font-weight: 400; background: #fff; color: var(--ink); width: 100%; }
input.mono { font-family: var(--mono); }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; }
.check input { width: 18px; height: 18px; margin-top: 3px; accent-color: var(--pri); flex: none; }
.optbox { display: flex; gap: 12px; align-items: flex-start; padding: 14px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.optbox input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--pri); flex: none; }
.optbox b { display: block; font-size: 15px; font-weight: 600; } .optbox span { font-size: 13px; color: var(--muted); }

.alert { border-radius: 12px; padding: 12px 16px; font-size: 14px; border: 1px solid; }
.alert.ok { background: var(--ok-bg); color: var(--ok); border-color: #BFD8C3; }
.alert.err { background: var(--err-bg); color: var(--err); border-color: #E8BDB5; }
.alert.warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-line); }

.pill { display: inline-block; font-size: 13px; padding: 2px 10px; border-radius: 999px; white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok); } .pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.off { background: var(--line-2); color: var(--ink-2); } .pill.pri { background: var(--pri-soft); color: var(--pri-ink); font-size: 12px; }

.tablebox { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: left; color: var(--muted); font-size: 13px; font-weight: 500; padding: 12px; }
table.t td { padding: 12px; border-top: 1px solid var(--line-2); vertical-align: middle; }
table.t th:first-child, table.t td:first-child { padding-left: 20px; } table.t th:last-child, table.t td:last-child { padding-right: 20px; }
table.t tr.sel td { background: #EEF5F7; }
.empty { text-align: center; color: var(--muted); padding: 28px; }

.credbox { background: var(--paper); border: 1px dashed var(--field); border-radius: 12px; padding: 18px; display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; align-items: center; }
.credbox code { font-family: var(--mono); font-size: 17px; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; word-break: break-all; }

.prov { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 10px; }
.prov.locked { background: var(--paper); }
.prov .nm { flex: 1 1 240px; min-width: 0; } .prov .nm b { display: block; font-weight: 600; } .prov .nm span { font-size: 13px; color: var(--muted); font-family: var(--mono); overflow-wrap: anywhere; }
details.keyform { flex-basis: 100%; } details.keyform summary { cursor: pointer; color: var(--pri); font-size: 14px; }
details.keyform .row { margin-top: 10px; }

table.matrix td, table.matrix th { text-align: center; } table.matrix td:first-child, table.matrix th:first-child { text-align: left; }
.tog { position: relative; display: inline-block; width: 44px; height: 44px; }
.tog input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.tog span { position: absolute; inset: 4px; border-radius: 10px; border: 1px solid var(--field); background: #fff; display: grid; place-items: center; color: #fff; pointer-events: none; }
.tog input:checked + span { background: var(--pri); border-color: var(--pri); }
.tog input:focus-visible + span { outline: 2px solid var(--pri); outline-offset: 2px; }
.tog svg { width: 18px; height: 18px; opacity: 0; } .tog input:checked + span svg { opacity: 1; }

/* หน้าเข้าสู่ระบบ */
.login { display: flex; flex-wrap: wrap; min-height: 100vh; }
.login .art { flex: 1 1 420px; background: var(--navy); color: var(--navy-ink); padding: 56px; display: flex; flex-direction: column; justify-content: space-between; gap: 48px; }
.login .art h1 { font-size: 36px; line-height: 1.3; max-width: 480px; }
.login .art p { color: #C3CBD8; font-size: 17px; max-width: 460px; }
.login .art .brand .mark { background: var(--navy-ink); color: var(--navy); }
.login .form { flex: 1 1 480px; display: flex; align-items: center; justify-content: center; padding: 56px 24px; }
.login .box { width: 100%; max-width: 420px; background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 36px; display: flex; flex-direction: column; gap: 18px; }

/* ห่อโมดูล OCR เดิมให้เข้ากับธีม */
.ocr-wrap { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 20px; }
.engine-note { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; font-size: 14px; color: var(--muted); }
.ocr-steprow { display: flex; align-items: stretch; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.ocr-step { flex: 1; min-width: 200px; display: flex; gap: 12px; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.ocr-step-click { cursor: pointer; } .ocr-step-click:hover { border-color: var(--pri); background: #F7FAFB; }
.ocr-step-num { width: 28px; height: 28px; flex: none; border-radius: 50%; background: var(--pri); color: #fff; display: grid; place-items: center; font-weight: 600; font-size: 13px; }
.ocr-step-tx h4 { margin: 0 0 2px; font-size: 15px; font-weight: 600; } .ocr-step-tx p { margin: 0; font-size: 13px; color: var(--muted); }
.ocr-step-arrow { align-self: center; color: var(--field); font-size: 22px; }
.ocr-clear-btn { border: 1px solid #E2B8B1; background: #fff; color: var(--err); border-radius: 10px; padding: 0 16px; font: inherit; font-weight: 600; cursor: pointer; min-height: 44px; }
.file-input { margin-top: 8px; font-size: 13px; max-width: 100%; }
.status-text { font-size: 13px; color: var(--pri); margin: 6px 0 0; min-height: 15px; }
.preview-header h3 { margin: 0; font-size: 16px; font-weight: 600; } .preview-header p { margin: 2px 0 12px; font-size: 13px; color: var(--muted); }
.table-scroll { overflow: auto; border: 1px solid var(--line-2); border-radius: 8px; max-height: 70vh; }
.preview-table { width: 100%; border-collapse: collapse; font-size: 13px; white-space: nowrap; }
.preview-table th { background: var(--pri-soft); color: var(--pri-ink); text-align: left; padding: 9px 10px; position: sticky; top: 0; font-weight: 600; }
.preview-table td { padding: 7px 10px; border-top: 1px solid var(--line-2); }
.preview-table .text-right { text-align: right; font-family: var(--mono); }
.editable-cell { cursor: pointer; } .editable-cell:hover { background: #FDF6E8; }
.empty-preview { text-align: center; color: var(--muted); padding: 22px; }
