:root {
  --bg: #f6f4ef; --card: #fff; --ink: #1f2328; --muted: #6b6f76; --line: #e3dfd6;
  --brand: #8a3b12; --brand-ink: #fff; --ok: #1f7a4d; --warn: #b26a00; --bad: #b42318;
  --in: #2f6fb0; --out: #c4622d;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand); }
h1 { font-size: 1.35rem; margin: .4rem 0 1rem; }
h2 { font-size: 1.05rem; margin: 0 0 .6rem; }
h3 { font-size: .95rem; margin: 1rem 0 .4rem; }
main { padding: 1rem; max-width: 1200px; margin: 0 auto; }

.topbar { background: var(--brand); color: var(--brand-ink); padding: .5rem 1rem; display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; }
.topbar a, .topbar .link { color: var(--brand-ink); text-decoration: none; }
.brand { font-weight: 700; font-size: 1.1rem; }
.branch-name { opacity: .9; }
.topbar nav { display: flex; flex-wrap: wrap; gap: .25rem .9rem; align-items: center; margin-left: auto; }
.topbar select { padding: .25rem; border-radius: 6px; border: 0; }
form.inline { display: inline; }
button.link { background: none; border: 0; padding: 0; font: inherit; cursor: pointer; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 1rem; margin-bottom: 1rem; }
.card.narrow { max-width: 380px; margin: 3rem auto; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; }
.grid2 .card { margin: 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: .75rem; }
.tile span { display: block; color: var(--muted); font-size: .8rem; }
.tile b { font-size: 1.2rem; }
.tile small { display: block; color: var(--muted); }
.tile.warn { border-color: var(--warn); }

table { width: 100%; border-collapse: collapse; }
th, td { padding: .4rem .5rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
tr.total td { font-weight: 700; border-top: 2px solid var(--line); }
tr.bad td { background: #fdecea; }
tr.warnrow td { background: #fff4e0; }
tr.cancelled td { color: var(--muted); text-decoration: line-through; }
.scroll { overflow-x: auto; }
.register th, .register td { padding: .3rem .4rem; font-size: .85rem; }
.register td:nth-child(2) { min-width: 180px; }

.muted { color: var(--muted); }
.bad-text { color: var(--bad); }
.msg { padding: .6rem .8rem; border-radius: 8px; margin-bottom: .8rem; background: #eef4ff; }
.msg.success { background: #e7f6ee; color: var(--ok); }
.msg.error { background: #fdecea; color: var(--bad); }
.msg.warning { background: #fff4e0; color: var(--warn); }
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 99px; font-size: .75rem; font-weight: 600; vertical-align: middle; }
.badge.ok { background: #e7f6ee; color: var(--ok); }
.badge.closed { background: #eee; color: var(--muted); }

label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .6rem; }
input, select { display: block; width: 100%; margin-top: .2rem; padding: .55rem .6rem; font: inherit; color: var(--ink);
  border: 1px solid #cfc9bd; border-radius: 8px; background: #fff; }
input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: 0; }
button, .button { display: inline-block; padding: .55rem 1rem; font: inherit; border-radius: 8px; border: 1px solid transparent;
  cursor: pointer; text-decoration: none; }
.primary { background: var(--brand); color: #fff; }
.secondary { background: #fff; border-color: #cfc9bd; color: var(--ink); }
.danger { background: #fff; border-color: var(--bad); color: var(--bad); }
.actions { display: flex; flex-wrap: wrap; gap: .6rem; align-items: end; }
.actions .wide { flex: 1 1 260px; margin: 0; }

.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 1rem; }
.fields .wide { grid-column: 1 / -1; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.filters input, .filters select { width: auto; min-width: 180px; margin: 0; }
.filters .check { display: flex; gap: .3rem; align-items: center; margin: 0; }
.filters .check input { width: auto; margin: 0; }
.daynav { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.daynav input { width: auto; margin: 0; }
dl.meta { display: grid; grid-template-columns: max-content 1fr; gap: .2rem 1rem; margin: 0 0 1rem; }
dl.meta dt { color: var(--muted); }
dl.meta dd { margin: 0; }

.lines { margin: .5rem 0 1rem; }
.line-head { display: none; }
.line-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: .4rem; padding: .6rem 0; border-bottom: 1px dashed var(--line); }
.line-row .c-item { grid-column: 1 / -1; }
.line-row label { margin: 0; }
.line-row .remove { align-self: end; background: none; border: 1px solid var(--line); color: var(--bad); width: 2.4rem; height: 2.4rem; padding: 0; }
.hint { display: block; min-height: 1.1em; color: var(--muted); }
.hint.bad { color: var(--bad); }
.sr { position: absolute; left: -9999px; }
.total-line { margin: .5rem 0 1rem; }

@media (min-width: 760px) {
  .line-head { display: flex; gap: .4rem; font-size: .8rem; color: var(--muted); }
  .line-head span, .line-row > label { flex: 0 0 auto; }
  .line-row { display: flex; align-items: start; }
  .line-row .c-item, .line-head .c-item { flex: 1 1 auto; }
  .c-qty, .c-rate { width: 110px; }
  .c-date { width: 150px; }
  .line-head .c-item { margin-right: 2.8rem; }
}

table.bars td { border: 0; padding: .2rem .3rem; }
.barcell { width: 60%; }
.bar { height: 7px; border-radius: 4px; margin: 2px 0; min-width: 2px; }
.bar.in, .key.in { background: var(--in); }
.bar.out, .key.out { background: var(--out); }
.legend { font-size: .8rem; color: var(--muted); }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin: 0 .2rem 0 .6rem; }

/* Daily sheet (Excel-like grid) */
.sheet-wrap { overflow: auto; max-height: calc(100vh - 230px); border: 1px solid var(--line); border-radius: 10px; background: #fff; }
table.sheet { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; }
table.sheet th, table.sheet td { padding: 0; border-bottom: 1px solid var(--line); border-right: 1px solid #f0ece4; font-size: .85rem; }
table.sheet th { position: sticky; top: 0; z-index: 2; background: #f3efe6; padding: .4rem .35rem; color: var(--ink); }
table.sheet td.num, table.sheet td.c-code, table.sheet td.c-name { padding: .3rem .4rem; white-space: nowrap; }
table.sheet .c-code { position: sticky; left: 0; background: #fff; z-index: 1; }
table.sheet .c-name { position: sticky; left: 5.6rem; background: #fff; z-index: 1; min-width: 12rem; max-width: 16rem; overflow: hidden; text-overflow: ellipsis; }
table.sheet th.c-code, table.sheet th.c-name { z-index: 3; background: #f3efe6; }
table.sheet input.cell { width: 4.6rem; margin: 0; padding: .3rem .35rem; border: 0; border-radius: 0; text-align: right; background: transparent; }
table.sheet input.cell:focus { outline: 2px solid var(--brand); background: #fffdf6; }
table.sheet input.cell:disabled { color: var(--ink); }
table.sheet .in-col { background: #f5f9ff; }
table.sheet input.rate.missing { background: #fdecea; }
table.sheet tr.changed td.c-code, table.sheet tr.changed td.c-name { background: #fff4e0; }
table.sheet tr.bad td { background: #fdecea; }
table.sheet .closing { font-weight: 600; }
.sheet-save { position: sticky; bottom: 0; display: flex; flex-wrap: wrap; gap: .75rem; align-items: end; background: var(--bg);
  padding: .75rem 0; border-top: 1px solid var(--line); margin-top: .5rem; }
.sheet-save .wide { flex: 1 1 260px; margin: 0; }
