:root{
  --bg:#f4f6f8; --card:#fff; --line:#e2e7ec; --line-strong:#cfd7de;
  --text:#232b31; --muted:#6f7c86; --accent:#1f6f5c; --accent-soft:#e8f2ef;
  --danger:#b4342c; --radius:10px;
}
*{box-sizing:border-box}
body{margin:0;background:var(--bg);color:var(--text);
  font-family:'Cairo','Segoe UI',Tahoma,sans-serif;font-size:15px;line-height:1.7}
a{color:var(--accent);text-decoration:none}
a:hover{text-decoration:underline}

.topbar{background:#fff;border-bottom:1px solid var(--line)}
.topbar .inner{max-width:1080px;margin:0 auto;padding:14px 20px;display:flex;align-items:center;gap:16px}
.topbar h1{font-size:17px;margin:0;font-weight:700}
.topbar .spacer{flex:1}

.wrap{max-width:1080px;margin:24px auto 60px;padding:0 20px}
.card{background:var(--card);border:1px solid var(--line);border-radius:var(--radius);padding:22px}
.card + .card{margin-top:18px}
.card h2{margin:0 0 16px;font-size:16px}

.btn{display:inline-block;border:1px solid var(--line-strong);background:#fff;color:var(--text);
  padding:8px 16px;border-radius:8px;font:inherit;font-size:14px;cursor:pointer;text-decoration:none}
.btn:hover{background:#f7f9fa;text-decoration:none}
.btn.primary{background:var(--accent);border-color:var(--accent);color:#fff}
.btn.primary:hover{background:#1a5e4e}
.btn.danger{color:var(--danger);border-color:#e6c9c6}
.btn.danger:hover{background:#fdf4f3}
.btn.sm{padding:5px 11px;font-size:13px}

.toolbar{display:flex;gap:10px;align-items:center;margin-bottom:16px;flex-wrap:wrap}
.toolbar form{display:flex;gap:8px;flex:1;min-width:240px}
input[type=text],input[type=date],input[type=search],textarea,select{
  width:100%;padding:9px 12px;border:1px solid var(--line-strong);border-radius:8px;
  font:inherit;font-size:14px;background:#fff;color:var(--text)}
input:focus,textarea:focus,select:focus{outline:2px solid var(--accent-soft);border-color:var(--accent)}
textarea{resize:vertical;min-height:70px}
input[type=file],input[type=number],input[type=password]{width:100%;padding:9px 12px;
  border:1px solid var(--line-strong);border-radius:8px;font:inherit;font-size:14px;background:#fff;color:var(--text)}
input:disabled{background:#f2f5f7;color:var(--muted)}

.grid{display:grid;grid-template-columns:1fr 1fr;gap:14px 18px}
.field label{display:block;font-size:13px;color:var(--muted);margin-bottom:5px;font-weight:600}
.field.full{grid-column:1/-1}
.ltr{direction:ltr;text-align:right}
fieldset{border:0;padding:0;margin:0 0 22px}
fieldset legend{font-weight:700;font-size:14px;padding:0;margin-bottom:12px;
  color:var(--accent);border-bottom:1px solid var(--line);width:100%;padding-bottom:8px}

table.list{width:100%;border-collapse:collapse}
table.list th,table.list td{padding:11px 12px;border-bottom:1px solid var(--line);text-align:right;font-size:14px}
table.list th{font-size:12.5px;color:var(--muted);font-weight:700;background:#fafbfc}
table.list tr:last-child td{border-bottom:0}
table.list td.num{direction:ltr;text-align:right;white-space:nowrap}
table.list td.actions{white-space:nowrap;text-align:left}
table.list td.actions form{display:inline}

.empty{text-align:center;color:var(--muted);padding:44px 10px}
.flash{background:var(--accent-soft);border:1px solid #cfe3dc;color:#14513f;
  padding:11px 15px;border-radius:8px;margin-bottom:16px;font-size:14px}
.flash.error{background:#fdf4f3;border-color:#e6c9c6;color:var(--danger)}

body.centered{display:flex;align-items:center;justify-content:center;min-height:100vh;padding:20px}
.login{background:var(--card);border:1px solid var(--line);border-radius:var(--radius);
  padding:30px;width:100%;max-width:380px}
.login h1{margin:0 0 4px;font-size:19px}
.login p.muted{margin:0 0 20px}

.filters{display:flex;align-items:center;gap:8px;flex-wrap:wrap;margin-bottom:16px;
  padding-bottom:14px;border-bottom:1px solid var(--line)}
.filter{display:inline-flex;align-items:center;gap:7px;padding:6px 14px;border-radius:999px;
  border:1px solid var(--line-strong);font-size:13.5px;color:var(--text);text-decoration:none}
.filter:hover{background:#f7f9fa;text-decoration:none}
.filter.on{background:var(--accent);border-color:var(--accent);color:#fff}
.filter .n{font-size:12px;opacity:.75}

.chip{display:inline-block;padding:3px 11px;border-radius:999px;font-size:12.5px;
  font-weight:700;color:#fff;white-space:nowrap}
.chip.ok{background:#2e8b57}
.chip.warn{background:#b07514}
.chip.gray{background:#7a838d}
.muted{color:var(--muted);font-size:13px}
.actions-row{display:flex;gap:10px;align-items:center;margin-top:8px;flex-wrap:wrap}

.code{direction:ltr;unicode-bidi:embed;font-family:ui-monospace,SFMono-Regular,Consolas,monospace;
  font-size:12.5px;background:#f0f3f5;border:1px solid var(--line);border-radius:5px;padding:1px 6px}

/* a checkbox with its caption on one line */
.chk{display:inline-flex;align-items:center;gap:8px;font-size:13.5px;font-weight:600;
  color:var(--text);cursor:pointer;white-space:nowrap}
.chk input[type=checkbox]{width:18px;height:18px;cursor:pointer;margin:0}

/* settings: section + field ordering blocks */
.sec-block{border:1px solid var(--line);border-radius:8px;padding:14px 16px;margin-bottom:14px;background:#fafbfc}
.sec-block.off{opacity:.55}
.sec-top{display:grid;grid-template-columns:1fr 110px auto;gap:12px;align-items:end;margin-bottom:12px}
.sec-top .chk{padding-bottom:9px}
.fld-head{display:grid;grid-template-columns:1fr 110px 60px;gap:12px;font-size:12px;
  color:var(--muted);font-weight:700;padding:0 0 6px;border-bottom:1px solid var(--line)}
.fld-head span:nth-child(2),.fld-head span:nth-child(3){text-align:center}
.fld-row{display:grid;grid-template-columns:1fr 110px 60px;gap:12px;align-items:center;
  padding:8px 0;border-bottom:1px solid var(--line)}
.fld-row:last-child{border-bottom:0}
.fld-row.off{opacity:.5}
.fld-row .fl{display:flex;flex-direction:column;gap:3px}
/* QR page: the boxes table */
.boxes{border:1px solid var(--line);border-radius:8px;overflow:hidden;margin-bottom:4px}
.box-row{display:grid;grid-template-columns:1fr 90px 60px;gap:10px;align-items:center;
  padding:8px 12px;border-bottom:1px solid var(--line)}
.box-row:last-child{border-bottom:0}
.box-row.off{opacity:.5}
.box-head{background:#fafbfc;font-size:12.5px;color:var(--muted);font-weight:700}
.box-row input[type=checkbox]{width:18px;height:18px;justify-self:center;cursor:pointer}
.box-row input[type=number]{text-align:center;padding:6px 8px;font-size:13px}

/* QR page: one flat field list, grouped by box, reordered by dragging or with the arrows */
.qfields{border:1px solid var(--line);border-radius:8px;overflow:hidden}
.qf2-box{background:#eef2f5;padding:7px 12px;font-size:12.5px;font-weight:700;color:var(--accent)}
.qf2-empty{padding:8px 12px;font-size:12.5px;color:var(--muted)}
.qf2-row{display:grid;grid-template-columns:24px 1fr 1.2fr 1fr 104px 50px;gap:10px;align-items:center;
  padding:8px 12px;border-bottom:1px solid var(--line);background:#fff}
.qf2-row:last-child{border-bottom:0}
.qf2-row.off{opacity:.5}
.qf2-row .nm{font-size:13px;font-weight:600}
.qf2-row input[type=text],.qf2-row select{padding:6px 8px;font-size:13px}
.qf2-row input[type=checkbox]{width:18px;height:18px;justify-self:center;cursor:pointer}
.qf2-row .mv{display:flex;align-items:center;gap:4px}
.qf2-row .arrow{border:1px solid var(--line-strong);background:#fff;border-radius:6px;
  width:26px;height:28px;cursor:pointer;font-size:11px;line-height:1;padding:0;color:var(--text)}
.qf2-row .arrow:hover{background:var(--accent-soft);border-color:var(--accent)}
.qf2-row .ord{width:44px;text-align:center;padding:6px 4px;font-size:13px}
.sub-label{display:block;margin:8px 0 4px;font-size:12px;color:var(--muted);font-weight:600}
.qf2-row .grip{cursor:grab;color:var(--muted);font-size:17px;line-height:1;text-align:center;
  user-select:none;border-radius:5px;padding:2px 0}
.qf2-row .grip:hover{color:var(--accent);background:var(--accent-soft)}
.qf2-row .grip:active{cursor:grabbing}
.qf2-row.dragging{opacity:.45;outline:2px dashed var(--accent);outline-offset:-2px}
@media (max-width:720px){
  .qf2-row{grid-template-columns:24px 1fr 1fr}
  .qf2-row .nm{grid-column:2/-1}
  .box-row{grid-template-columns:1fr 70px 40px}
}
/* the QR page's closing block: one row per text line */
.qf-rows{border:1px solid var(--line);border-radius:8px;overflow:hidden;margin-top:4px}
.qf-head,.qf-row{display:grid;grid-template-columns:1fr 2fr 1.2fr 76px;gap:10px;
  align-items:center;padding:9px 12px;border-bottom:1px solid var(--line)}
.qf-row:last-child{border-bottom:0}
.qf-head{background:#fafbfc;font-size:12.5px;color:var(--muted);font-weight:700}
.qf-row .nm{font-size:13.5px;font-weight:600}
.qf-row select,.qf-row input{padding:6px 8px;font-size:13px}
.qf-row input[type=number]{text-align:center}
@media (max-width:720px){ .qf-head{display:none} .qf-row{grid-template-columns:1fr 1fr} .qf-row .nm{grid-column:1/-1} }

/* contents list at the top of the settings screen */
.toc{display:grid;grid-template-columns:1fr 1fr;gap:18px;font-size:13.5px}
.toc strong{display:block;margin-bottom:6px;color:var(--accent)}
.toc ol{margin:0;padding-inline-start:22px;color:var(--muted);line-height:1.9}

/* the save row, kept in reach at the bottom of the form */
.save-bar{position:sticky;bottom:12px;display:flex;align-items:center;gap:10px;flex-wrap:wrap;
  box-shadow:0 2px 14px rgba(0,0,0,.08)}

/* an explanatory callout inside a fieldset */
.hint{background:var(--accent-soft);border:1px solid #cfe3dc;border-radius:8px;
  padding:12px 15px;margin-bottom:14px;font-size:13.5px;line-height:1.9}
.hint strong{display:block;margin-bottom:4px;color:#14513f}
.hint p{margin:4px 0}
.hint ul{margin:6px 0;padding-inline-start:20px}
.hint li{margin:2px 0}

/* a sub-heading inside a fieldset, for grouping related blocks */
.sub-head{margin:18px 0 10px;font-weight:700;font-size:13.5px;color:var(--text);
  padding-bottom:6px;border-bottom:1px dashed var(--line)}
/* the independent QR ordering block is greyed while the page follows the document */
.dimmed{opacity:.5}

/* the QR-page element rows need room for an editable caption, not a sort number */
.qr-parts .fld-head,.qr-parts .fld-row{grid-template-columns:1fr 1.5fr 60px}
.qr-parts .fld-row .fl{justify-content:center;font-size:14px;font-weight:600}
.fld-row .fl .muted{font-size:11.5px}
.fld-row input[type=checkbox]{width:18px;height:18px;cursor:pointer;justify-self:center}

/* settings: per-element styling panel */
.sty{border:1px solid var(--line);border-radius:8px;overflow:hidden}
.sty-row{display:grid;grid-template-columns:1.15fr 1.15fr 68px 64px 50px 50px 92px;gap:9px;
  align-items:center;padding:9px 12px;border-bottom:1px solid var(--line)}
.sty-row input[type=number]{padding:6px 7px;font-size:13px;text-align:center}
.sty-row:last-child{border-bottom:0}
.sty-head{background:#fafbfc;font-size:12.5px;color:var(--muted);font-weight:700;text-align:center}
.sty-head span:first-child{text-align:right}
.sty-row .nm{font-size:14px;font-weight:600}
.sty-row select{width:100%;padding:6px 8px;font-size:13px}
.sty-row input[type=color]{width:100%;height:30px;padding:2px;border:1px solid var(--line-strong);
  border-radius:6px;background:#fff;cursor:pointer}
.sty-row input[type=checkbox]{width:18px;height:18px;cursor:pointer;justify-self:center}
.sty-row .bg{display:flex;align-items:center;gap:6px}
.sty-row .bg input[type=color]{flex:1}

/* settings: image slots */
.img-slot .img-thumb{display:flex;align-items:center;justify-content:center;height:70px;margin-bottom:8px;
  border:1px solid var(--line);border-radius:8px;background:#fff;overflow:hidden}
.img-slot .img-thumb img{max-height:60px;max-width:100%;object-fit:contain;display:block}
.img-slot .img-thumb.empty{color:var(--muted);font-size:12.5px;background:#fafbfc}

@media (max-width:720px){
  .grid{grid-template-columns:1fr}
  .wrap{padding:0 14px}
  .toc{grid-template-columns:1fr}
  .save-bar{position:static}
  .sec-top{grid-template-columns:1fr;gap:10px}
  .sec-top .chk{padding-bottom:0}
  .sty-row{grid-template-columns:1fr 1fr;gap:8px;row-gap:10px}
  .sty-head{display:none}
  .sty-row .nm{grid-column:1/-1}
}
