:root {
  --ink: #1f1c16; --gold: #8a6d2f; --gold-light: #f4f0e8; --rule: #d8cfb8;
  --grey: #6b6557; --bg: #faf8f4; --white: #fff; --red: #a33; --green: #2c7a4b;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, "Segoe UI", Arial, sans-serif; background: var(--bg); color: var(--ink); }
.hidden { display: none !important; }

/* login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { background: var(--white); border: 1px solid var(--rule); border-radius: 10px; padding: 40px; width: 360px; box-shadow: 0 8px 30px rgba(0,0,0,.06); }
.brand { color: var(--gold); font-weight: 700; letter-spacing: 3px; font-size: 13px; }
.login-card h1 { margin: 6px 0 2px; font-size: 22px; }
.login-card .sub { margin: 0 0 22px; color: var(--grey); font-size: 13px; }
label { display: block; font-size: 13px; color: var(--grey); margin-bottom: 12px; }
input, select, textarea { width: 100%; padding: 9px 10px; margin-top: 4px; border: 1px solid var(--rule); border-radius: 6px; font-size: 14px; background: var(--white); }
.error { color: var(--red); font-size: 13px; min-height: 18px; margin-bottom: 6px; }

/* layout */
.topbar { display: flex; align-items: center; gap: 18px; background: var(--white); border-bottom: 2px solid var(--gold); padding: 0 18px; height: 54px; position: sticky; top: 0; z-index: 10; flex-wrap: wrap; }
.brand-sm { color: var(--gold); font-weight: 700; letter-spacing: 2px; }
nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
nav a { padding: 16px 12px; text-decoration: none; color: var(--grey); font-size: 14px; white-space: nowrap; border-bottom: 3px solid transparent; }
nav a.active { color: var(--ink); border-bottom-color: var(--gold); font-weight: 600; }
.userbox { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--grey); }
main { padding: 22px; max-width: 1300px; margin: 0 auto; }

/* components */
h2.page-title { margin: 0 0 16px; font-size: 21px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 16px; }
.toolbar label { margin: 0; }
.toolbar input, .toolbar select { width: auto; min-width: 130px; }
.btn { padding: 9px 16px; border: 1px solid var(--rule); background: var(--white); border-radius: 6px; cursor: pointer; font-size: 14px; }
.btn.primary { background: var(--gold); border-color: var(--gold); color: #fff; font-weight: 600; }
.btn.ghost { border: none; background: none; color: var(--grey); }
.btn.danger { color: var(--red); }
.btn.wide { width: 100%; }
.btn:hover { opacity: .9; }

table.grid { width: 100%; border-collapse: collapse; background: var(--white); font-size: 13.5px; }
table.grid th { background: var(--gold-light); text-align: left; padding: 9px 10px; border: 1px solid var(--rule); font-size: 12.5px; }
table.grid td { padding: 8px 10px; border: 1px solid var(--rule); }
table.grid tr:hover td { background: #fdfcf9; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11.5px; background: var(--gold-light); color: var(--gold); font-weight: 600; }
.tag.green { background: #e7f3ec; color: var(--green); }
.tag.red { background: #f7e9e9; color: var(--red); }

/* dashboard cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; margin-bottom: 22px; }
.card { background: var(--white); border: 1px solid var(--rule); border-radius: 8px; padding: 14px 16px; }
.card .k { font-size: 12px; color: var(--grey); text-transform: uppercase; letter-spacing: .5px; }
.card .v { font-size: 22px; font-weight: 700; margin-top: 4px; }
.card .v.neg { color: var(--red); }
.branch-block { background: var(--white); border: 1px solid var(--rule); border-radius: 8px; padding: 16px 18px; margin-bottom: 16px; }
.branch-block h3 { margin: 0 0 10px; display: flex; justify-content: space-between; align-items: center; }
.kv-row { display: flex; flex-wrap: wrap; gap: 22px; font-size: 13.5px; }
.kv-row div span { color: var(--grey); display: block; font-size: 11.5px; text-transform: uppercase; }
.kv-row div b { font-size: 16px; }
.alerts { background: #fff8ee; border: 1px solid #ecd9b0; border-radius: 8px; padding: 12px 16px; margin-bottom: 18px; font-size: 13.5px; }
.alerts div { padding: 3px 0; }

/* modal */
#modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; z-index: 50; }
.modal { background: var(--white); border-radius: 10px; padding: 24px; width: 640px; max-width: 100%; }
.modal h3 { margin: 0 0 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }

/* report */
.report-sheet { background: var(--white); border: 1px solid var(--rule); border-radius: 8px; padding: 22px 26px; max-width: 760px; }
.report-sheet h3 { border-bottom: 2px solid var(--gold); padding-bottom: 8px; }
.rline { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px dashed var(--rule); font-size: 14px; }
.rline.total { font-weight: 700; border-bottom: 2px solid var(--ink); }
.rline .plus { color: var(--green); } .rline .minus { color: var(--red); }

@media (max-width: 760px) {
  .form-grid { grid-template-columns: 1fr; }
  main { padding: 14px; }
  table.grid { font-size: 12px; display: block; overflow-x: auto; }
}

/* v2 additions */
.gold-bar { background: #fffdf7; border-bottom: 1px solid var(--rule); padding: 8px 18px; font-size: 13.5px; color: var(--ink); display:flex; gap:8px; align-items:center; flex-wrap:wrap; }
.hint { background: #fffdf2; border: 1px dashed var(--rule); border-radius: 6px; padding: 8px 12px; font-size: 12.5px; color: var(--grey); margin-bottom: 12px; }
.login-top { display:flex; justify-content:space-between; align-items:center; }
.actions { white-space: nowrap; }
.jsoncell { max-width:260px; word-break:break-all; font-size:11.5px; color:var(--grey); }
[dir="rtl"] body, [dir="rtl"] input, [dir="rtl"] select, [dir="rtl"] textarea, [dir="rtl"] button { font-family: "Segoe UI", Tahoma, Arial, sans-serif; }
[dir="rtl"] table.grid th { text-align: right; }
[dir="rtl"] .num { text-align: left; }
.btn.tab { border-radius: 6px 6px 0 0; }
.btn.tab.active { background: var(--ink); color: #fff; }
tr.st-done td { color: #6a7a6a; }
tr.st-in_progress td { background: #fffbe9; }
.item-row { display:flex; gap:6px; align-items:center; margin-bottom:6px; flex-wrap:wrap; }
.item-row input, .item-row select { padding:7px 8px; border:1px solid var(--rule); border-radius:6px; font-size:13px; min-width:90px; flex:1; }
.item-row select { flex:0 0 auto; }
.item-row .rm-item { flex:0 0 auto; }
tr.low-row td { background: #fff4f2; }
.ws-sheet { border-inline-start: 4px solid #8a6d1d; }
