@font-face { font-family: 'UI Bengali'; src: url(/fonts/sans-bn.woff2) format('woff2'); font-weight: 100 900; unicode-range: U+0951-0952, U+0964-0965, U+0980-09FE, U+200C-200D, U+25CC; font-display: swap; }
@font-face { font-family: 'UI Bengali'; src: url(/fonts/sans-latin.woff2) format('woff2'); font-weight: 100 900; unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122, U+2212; font-display: swap; }
@font-face { font-family: 'Letter Serif'; src: url(/fonts/serif-bn.woff2) format('woff2'); font-weight: 100 900; unicode-range: U+0951-0952, U+0964-0965, U+0980-09FE, U+200C-200D, U+25CC; font-display: swap; }
@font-face { font-family: 'Letter Serif'; src: url(/fonts/serif-latin.woff2) format('woff2'); font-weight: 100 900; unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122, U+2212; font-display: swap; }

:root {
  --bg: #f4f6f9; --panel: #fff; --ink: #1d2733; --muted: #66727f; --line: #dde3ea; --line2: #eef1f5;
  --brand: #0b6e4f; --brand-ink: #fff; --brand-soft: #e6f3ee; --err: #b42318; --err-bg: #fef3f2; --warn: #8a5a00; --warn-bg: #fff8e6;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 'UI Bengali', system-ui, sans-serif; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); } .small { font-size: 12.5px; }
.err { color: var(--err); min-height: 1.2em; margin: 6px 0 0; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); background: var(--panel); padding: 28px; border-radius: 14px; box-shadow: var(--shadow); display: grid; gap: 12px; }
.brand-lg { font-size: 24px; color: var(--brand); } .brand-lg b, .brand b { font-weight: 700; }

/* top bar */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px; padding: 0 16px; height: 56px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { color: var(--brand); font-size: 18px; white-space: nowrap; }
.tabs { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.tabs button { border: 0; background: none; padding: 16px 12px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.me { display: flex; gap: 10px; align-items: center; white-space: nowrap; font-size: 13px; }
.link { border: 0; background: none; color: var(--brand); cursor: pointer; padding: 4px; }

main { padding: 16px; max-width: 1500px; margin: 0 auto; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.split { display: grid; grid-template-columns: minmax(340px, 440px) 1fr; gap: 16px; align-items: start; }
.form-panel { display: grid; gap: 12px; position: sticky; top: 72px; max-height: calc(100vh - 88px); overflow: auto; }
.preview-panel { padding: 0; overflow: hidden; }
.preview-head { padding: 10px 16px; border-bottom: 1px solid var(--line2); }
.paper-wrap { background: #e9edf2; padding: 20px; overflow: auto; }

/* forms */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.fld { display: grid; gap: 4px; min-width: 0; }
.fld > span { font-size: 12.5px; color: var(--muted); }
.wide { grid-column: 1 / -1; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; min-height: 38px; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
input:disabled, select:disabled, textarea:disabled { background: #f1f3f6; color: var(--muted); cursor: not-allowed; }
.chk { display: flex; gap: 8px; align-items: flex-start; } .chk input { width: auto; min-height: 0; margin-top: 4px; }
.row2 { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: end; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; width: max-content; }
.seg button { border: 0; background: #fff; padding: 7px 16px; cursor: pointer; }
.seg button.on { background: var(--brand); color: var(--brand-ink); }
.btn { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 8px 14px; cursor: pointer; min-height: 38px; white-space: nowrap; }
.btn:hover { border-color: #b9c3ce; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--err); border-color: #f2c4bf; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.sticky { position: sticky; bottom: -16px; background: var(--panel); padding: 12px 0 4px; border-top: 1px solid var(--line2); }
.msg { border-radius: 8px; padding: 8px 12px; margin: 0 0 6px; font-size: 13px; }
.msg.e { background: var(--err-bg); color: var(--err); } .msg.n { background: var(--warn-bg); color: var(--warn); }
.salbox { background: var(--brand-soft); border-radius: 8px; padding: 10px 12px; font-size: 13px; display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; }
.salbox b { text-align: right; } .salbox .h { grid-column: 1 / -1; font-weight: 600; color: var(--brand); margin-bottom: 2px; }
.group-title { grid-column: 1 / -1; font-weight: 600; margin-top: 6px; padding-top: 8px; border-top: 1px solid var(--line2); }

/* tables */
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; } .toolbar input { flex: 1; min-width: 200px; } .toolbar select { width: auto; }
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-weight: 600; color: var(--muted); background: #f8fafc; }
.tbl th, .tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line2); white-space: nowrap; }
.tbl td.wrap { white-space: normal; min-width: 160px; }
.tbl tr:hover td { background: #fafcfd; }
.tbl .acts { display: flex; gap: 6px; } .tbl .btn { min-height: 30px; padding: 4px 10px; font-size: 12.5px; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 99px; background: var(--line2); font-size: 12px; }
.tag.ok { background: var(--brand-soft); color: var(--brand); }

.settings { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; max-width: 980px; }
.dept-row { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 8px; grid-column: 1 / -1; }

dialog { border: 0; border-radius: 14px; padding: 0; width: min(760px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(15,23,32,.45); }
#dlgForm { padding: 20px; display: grid; gap: 12px; max-height: calc(100vh - 64px); overflow: auto; }
.dlg-title { font-size: 17px; font-weight: 600; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1d2733; color: #fff; padding: 10px 16px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 50; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; }

/* ---------- letter (screen + print) ---------- */
.paper { width: 210mm; max-width: 100%; min-height: 297mm; margin: 0 auto; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.12); padding: 0 var(--side, 20mm); display: flex; flex-direction: column; }
.lh-space { flex: none; margin: 0 calc(-1 * var(--side, 20mm)); border: 1px dashed #c7d0da; background: repeating-linear-gradient(-45deg, #fafbfc 0 8px, #f3f5f8 8px 16px); display: grid; place-items: center; color: #9aa6b2; font: 12px 'UI Bengali', sans-serif; }
.lh-space.top { height: var(--lh-top, 45mm); margin-bottom: 6mm; } .lh-space.bottom { height: var(--lh-bottom, 25mm); margin-top: auto; }
.lh-space.top::after { content: 'লেটারহেডের জায়গা (উপরে)'; } .lh-space.bottom::after { content: 'লেটারহেডের জায়গা (নিচে)'; }
.letter { font-family: 'Letter Serif', 'Noto Serif Bengali', serif; font-size: 10.5pt; line-height: 1.5; color: #111; padding-bottom: 8mm; }
.letter p { margin: 0 0 2.6mm; text-align: justify; }
.letter[contenteditable="true"] { outline: 2px dashed var(--brand); outline-offset: 4px; }
.lt-meta { display: flex; justify-content: space-between; gap: 10mm; margin-bottom: 5mm; }
.lt-to { margin-bottom: 4mm; } .lt-subj { margin: 3mm 0 4mm; }
.lt-title { text-align: center; font-size: 15pt; margin: 4mm 0 5mm; text-decoration: underline; text-underline-offset: 4px; }
.center { text-align: center !important; }
.lt-terms { margin: 0 0 3mm; padding-left: 6mm; } .lt-terms > li { margin-bottom: 2.4mm; text-align: justify; }
.lt-table { border-collapse: collapse; width: 100%; margin: 2mm 0 2mm; font-size: 10.5pt; }
.lt-table th, .lt-table td { border: 0.6pt solid #555; padding: 1.2mm 2.4mm; text-align: left; vertical-align: top; }
.lt-table th { background: #f2f2f2; } .lt-table .r { text-align: right; white-space: nowrap; } .lt-table .tot td { font-weight: 700; }
.words { font-style: italic; font-size: 10.5pt; }
.cite { color: #444; font-size: 9.5pt; }
.small { font-size: 9.5pt; }
.lt-sign { margin-top: 6mm; break-inside: avoid; } .sig-space { height: 16mm; }
.lt-ack { margin-top: 7mm; border-top: 0.8pt solid #333; padding-top: 3mm; break-inside: avoid; }
.ack-title { font-weight: 700; margin-bottom: 2mm; }
.ack-lines { display: flex; flex-wrap: wrap; gap: 4mm 10mm; margin-top: 6mm; }
.ack-col { display: grid; gap: 4mm; margin-top: 8mm; }
.lt-name { font-size: 12pt; } .lt-subj u { text-underline-offset: 3px; }
.blank-lines { height: 18mm; border-bottom: 0.5pt dotted #777; }
.lt-copy { margin-top: 6mm; font-size: 9.5pt; color: #333; }
.ph { background: #fff3c4; color: #8a5a00; padding: 0 2px; border-radius: 2px; }
@counter-style bn-alpha { system: alphabetic; symbols: 'ক' 'খ' 'গ' 'ঘ' 'ঙ' 'চ' 'ছ' 'জ' 'ঝ' 'ঞ'; prefix: '('; suffix: ') '; }
.lt-terms.bn { list-style-type: bengali; } .lt-terms.bn .lt-sub { list-style-type: bn-alpha; }
.lt-table tr { break-inside: avoid; } .lt-sub { margin: 1mm 0 0; padding-left: 7mm; list-style-type: lower-alpha; } .lt-sub > li { margin-bottom: 1.4mm; text-align: justify; }
.lt-table thead { display: table-header-group; }

#print-area { display: none; }
@media print {
  body { background: #fff; }
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block; }
  #print-area .letter { padding: 0; }
  .ph { background: none; }
}

@media (max-width: 960px) {
  .split { grid-template-columns: 1fr; }
  .form-panel { position: static; max-height: none; }
  .paper-wrap { padding: 8px; }
  .paper { padding: 0 5mm; min-height: 0; }
  .lh-space { margin: 0 -5mm; }
}
@media (max-width: 560px) {
  main { padding: 10px; }
  .top { gap: 8px; padding: 0 10px; flex-wrap: wrap; height: auto; padding-top: 8px; }
  .tabs { order: 3; flex-basis: 100%; }
  .me { margin-left: auto; }
  .grid, .settings { grid-template-columns: 1fr; }
  .dept-row { grid-template-columns: 1fr 1fr; }
  .letter { font-size: 10pt; }
  .lt-meta { flex-direction: column; gap: 1mm; }
}
