/* VAF AGENT — one stylesheet, no build step.
   Bump ?v= in app/deps.py (ASSET_V) after editing, or browsers serve the old
   file and a fix nobody can see is a fix nobody can debug. */

:root {
  --bg: #0f1216;
  --panel: #171b21;
  --panel-2: #1e242c;
  --line: #2a323c;
  --text: #e6edf3;
  --dim: #94a3b8;
  --dimmer: #64748b;
  --accent: #38bdf8;
  --accent-2: #0ea5e9;
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
  --gold: #eab308;
  --radius: 10px;
  --gap: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: "Noto Sans Thai", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14.5px; line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 8px; font-weight: 650; line-height: 1.3; }
h1 { font-size: 20px; } h2 { font-size: 17px; } h3 { font-size: 15px; }
code, .mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12.5px; }

/* ── chrome ───────────────────────────────────────────── */
.top {
  display: flex; align-items: center; gap: 14px;
  padding: 0 16px; height: 50px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
}
.top .brand { font-weight: 700; letter-spacing: .3px; white-space: nowrap; }
.top nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.top nav a {
  padding: 6px 11px; border-radius: 8px; color: var(--dim); font-size: 13.5px;
}
.top nav a:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.top nav a.on { background: var(--panel-2); color: var(--text); }
.top .bal {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 4px 10px; font-weight: 650; white-space: nowrap;
}
.top form { margin: 0; }

/* Two languages, so both are always on screen and the current one is lit —
   a menu would hide the only other choice behind a click. */
.langsw {
  display: inline-flex; border: 1px solid var(--line); border-radius: 8px;
  overflow: hidden; flex: 0 0 auto;
}
.langsw a {
  padding: 4px 9px; font-size: 12px; font-weight: 650; color: var(--dim);
  text-decoration: none; line-height: 1.5;
}
.langsw a + a { border-left: 1px solid var(--line); }
.langsw a:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.langsw a.on { background: var(--accent-2); color: #041018; }

.wrap { padding: 16px; max-width: 1500px; margin: 0 auto; }

/* ── panels ───────────────────────────────────────────── */
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin-bottom: var(--gap);
}
.card > h2, .card > h3 { display: flex; align-items: center; gap: 8px; }
.muted { color: var(--dim); }
.dimmer { color: var(--dimmer); }
.small { font-size: 12.5px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.spacer { flex: 1 1 auto; }

/* ── forms ────────────────────────────────────────────── */
input[type=text], input[type=password], input[type=email], input[type=number],
select, textarea {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 10px; font: inherit; font-size: 14px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-2); outline-offset: -1px; }
label.field { display: block; margin-bottom: 10px; }
label.field > span { display: block; color: var(--dim); font-size: 12.5px; margin-bottom: 3px; }
/* Every input dropped inside .field is 100% wide — so a narrow one must carry
   TWO classes or this wins on specificity and stretches it across the row. */
.field input, .field select, .field textarea { width: 100%; }

.btn {
  background: var(--accent-2); color: #041018; border: 0; border-radius: 8px;
  padding: 8px 14px; font: inherit; font-weight: 650; cursor: pointer;
}
.btn:hover { background: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
.btn.ghost:hover { background: var(--line); }
.btn.gold { background: var(--gold); color: #20160a; }
.btn.danger { background: #7f1d1d; color: #fee2e2; }
.mini {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 7px; padding: 3px 8px; font: inherit; font-size: 12.5px;
  cursor: pointer;
}
.mini:hover { background: var(--line); }
.mini.on { background: var(--accent-2); color: #041018; border-color: var(--accent-2); }
/* A count riding inside a chip. Selected, the chip goes bright and near-black,
   and a fixed grey on top of that is the one combination nobody can read — so
   it follows the chip's own colour and just steps back from it. */
.mini .dimmer { color: var(--dimmer); }
.mini.on .dimmer { color: inherit; opacity: .6; }

/* ── tables ───────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; }
th, td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; }
th { color: var(--dim); font-weight: 600; font-size: 12.5px; }
tr:last-child td { border-bottom: 0; }

/* ── flashes / notices ────────────────────────────────── */
.flash {
  padding: 9px 13px; border-radius: 8px; margin-bottom: var(--gap);
  border: 1px solid var(--line); background: var(--panel-2);
}
.flash.ok  { border-color: #14532d; background: #08211544; }
.flash.err { border-color: #7f1d1d; background: #2a101044; }
.tag {
  display: inline-block; padding: 1px 7px; border-radius: 999px;
  font-size: 11.5px; border: 1px solid var(--line); background: var(--panel-2);
  color: var(--dim);
}
.tag.ok   { color: var(--ok);   border-color: #14532d; }
.tag.warn { color: var(--warn); border-color: #78350f; }
.tag.err  { color: var(--err);  border-color: #7f1d1d; }
.tag.gold { color: var(--gold); border-color: #713f12; }

/* ── toast ────────────────────────────────────────────── */
#toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none;
}
#toast div {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 9px 15px; border-radius: 10px; max-width: min(90vw, 520px);
  box-shadow: 0 8px 24px #0009;
}
#toast div.err { border-color: #7f1d1d; }
#toast div.ok  { border-color: #14532d; }

/* ── the console: three columns, screen height ────────── */
.con {
  display: grid; gap: var(--gap);
  grid-template-columns: 300px minmax(0, 1fr) 380px;
  height: calc(100vh - 50px); padding: var(--gap);
  max-width: 1700px; margin: 0 auto;
}
.col {
  display: flex; flex-direction: column; gap: var(--gap);
  min-height: 0; overflow-y: auto; padding-right: 2px;
}
.col::-webkit-scrollbar { width: 8px; }
.col::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
.con.loading { opacity: .5; pointer-events: none; }
.con [hidden] { display: none !important; }

.head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 0 var(--gap); height: 44px; border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.head .farmname { font-weight: 650; }
.head .stat { color: var(--dim); font-size: 13px; }
.head .stat b { color: var(--text); font-weight: 600; }
.head.editing { flex-wrap: wrap; }
.head .name-in { flex: 1 0 100%; }

/* item grid */
.grid {
  display: grid; gap: 8px;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
}
.it {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px;
  padding: 7px; cursor: pointer; text-align: center; position: relative;
  transition: border-color .1s;
}
.it:hover { border-color: var(--accent-2); }
.it.on { border-color: var(--accent); background: #0b2a3a; }
.it img { width: 40px; height: 40px; object-fit: contain; display: block; margin: 0 auto 3px; }
.it .n { font-size: 12px; line-height: 1.25; height: 2.5em; overflow: hidden; }
.it .q { font-size: 12.5px; font-weight: 650; color: var(--accent); }
.it .p { font-size: 11.5px; color: var(--dim); }
.it.out { opacity: .45; }

/* tabs and chips */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.tabs button {
  background: none; border: 0; border-bottom: 2px solid transparent;
  color: var(--dim); font: inherit; font-weight: 600; padding: 7px 12px; cursor: pointer;
}
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
.chips { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 9px; }

/* basket */
.basket { display: flex; flex-direction: column; gap: 6px; }
.bk {
  display: flex; gap: 7px; align-items: center;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 5px 8px;
}
/* Two lines per item: what is going out on top, what it costs underneath.
   Strung along one line instead, a phone gets a name column three characters
   wide — there are two number fields and a button to fit. Only the hand-over
   basket asks for it: `.bk` is shared, and turning the shared rule into a
   column once stacked the purchase basket's cells on top of each other. */
.bk.stacked { flex-direction: column; align-items: stretch; gap: 4px; }
.bk-top, .bk-bot { display: flex; gap: 7px; align-items: center; }
.bk img { width: 24px; height: 24px; object-fit: contain; }
.bk .n { flex: 1 1 auto; min-width: 0; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bk .sub { font-size: 11.5px; color: var(--dimmer); white-space: nowrap; }
/* The row's price is over what the game will take for its smallest lot. */
.bk .sub.over { color: var(--warn); }
.bk .bk-price.over { border-color: var(--warn); color: var(--warn); }
/* Two classes on purpose: `.field input{width:100%}` would stretch this to the
   whole row and leave the item name no space at all. */
.basket .bk-qty { width: 74px; flex: 0 0 74px; text-align: right; }

/* ── the shelf ────────────────────────────────────────
   A row per item, not a card per item. Cards were right for fourteen kinds and
   wrong for 230: four to a line and 150px tall each, finding one meant six
   thousand pixels of scrolling, and the quantity lived in a basket at the far
   end of it. A row carries its own number field, so choosing an item and
   saying how many is ONE action in ONE place, and 230 of them is a list you
   can read. */
.shop { display: flex; flex-direction: column; gap: 5px; }
.srow {
  display: flex; gap: 9px; align-items: center;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 9px; padding: 5px 9px;
}
.srow:hover { border-color: var(--line-2, var(--line)); }
.srow.on { border-color: var(--accent); background: #0b2a3a; }
.srow.out, .srow.locked { opacity: .5; }
.srow img { width: 30px; height: 30px; object-fit: contain; flex: 0 0 30px; }
/* width:0, not just min-width:0. The sub-line is `nowrap`, so its min-content is
   the whole sentence — "$0.001/pcs · 108 in stock [Needs level 8]" — and a flex
   item sized from its content hands that number up to the page grid, whose
   phone layout is a single `1fr` track that then grows past the viewport: the
   whole console scrolled sideways because of one long caption. A zero base size
   contributes nothing and still grows into the row. */
.srow .m { flex: 1 1 auto; width: 0; min-width: 0; }
.srow .n {
  display: block; font-size: 13px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.srow .sub {
  display: block; font-size: 11.5px; color: var(--dimmer);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.srow .bk-qty { width: 88px; flex: 0 0 88px; text-align: right; }
.srow .bk-qty.bad { border-color: var(--warn); color: var(--warn); }

/* The order control follows you down the list. It used to live under 230 cards,
   which made "how much is this costing me" a question you had to scroll to. */
.buybar {
  position: sticky; bottom: 0; z-index: 5;
  display: flex; gap: 9px; align-items: center; flex-wrap: wrap;
  margin: 10px 0 0; padding: 9px 12px;
  background: var(--panel); border: 1px solid var(--accent-2);
  border-radius: 10px; box-shadow: 0 -8px 20px #0009;
}

/* the slot board */
.board { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; }
.slot {
  aspect-ratio: 1; border-radius: 7px; border: 1px solid var(--line);
  background: var(--panel-2); display: flex; flex-direction: column;
  align-items: center; justify-content: center; font-size: 11px;
  cursor: pointer; position: relative; overflow: hidden; padding: 2px;
}
.slot img { width: 20px; height: 20px; object-fit: contain; }
.slot .q { font-weight: 650; font-size: 11px; line-height: 1.15; }
.slot .nm { font-size: 9px; line-height: 1.1; color: var(--dimmer);
            max-width: 100%; overflow: hidden; text-overflow: ellipsis;
            white-space: nowrap; }
/* top-LEFT: the name runs along the bottom and 💰 owns the top-right. */
.slot .more { position: absolute; top: 1px; left: 3px; font-size: 9px;
              color: var(--dimmer); }
.slot.empty { color: var(--dimmer); cursor: default; }
.slot.live { border-color: #1e3a5f; }
.slot.ghost { border: 1px dashed var(--ok); background: #06251b55; }
.slot.gold { border-color: var(--gold); background: #2a200855; }
.slot.sel { outline: 2px solid var(--accent); outline-offset: -2px; }
.slot .coin { position: absolute; top: 1px; right: 2px; font-size: 10px; }

/* friend / customer rows */
.plist { display: flex; flex-direction: column; gap: 5px; }
.p {
  display: flex; gap: 7px; align-items: center;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 8px; font-size: 13px;
}
.p .n { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p.on { border-color: var(--accent); }

/* delivery notes */
.note {
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px; font-size: 12.5px; margin-bottom: 6px;
}
.note .hd { display: flex; gap: 6px; align-items: center; margin-bottom: 4px; }
.note .hd .who { font-weight: 650; flex: 1 1 auto; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* progress */
.bar { height: 6px; background: var(--panel-2); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); transition: width .3s; }

/* ── phone ────────────────────────────────────────────── */
@media (max-width: 1000px) {
  .con { grid-template-columns: 1fr; height: auto; }
  .col { overflow: visible; }
  .wrap { padding: 12px; }
  /* Both bars are one fixed-height flex row on a wide screen. On a phone their
     content wraps to two lines, and a fixed height then lets the second line
     sit on top of whatever is below it — the nav landed across the farm row.
     So on a phone they grow instead. */
  .top, .head {
    height: auto; min-height: 46px; flex-wrap: wrap;
    padding-top: 6px; padding-bottom: 6px; row-gap: 4px;
  }
  .top { position: static; }
  .top nav { order: 3; flex: 1 0 100%; }
  /* iOS zooms a focused input under 16px and never zooms back out. */
  input[type=text], input[type=password], input[type=email], input[type=number],
  select, textarea { font-size: 16px; }
  .basket .bk-qty { width: 84px; flex: 0 0 84px; font-size: 16px; }
  /* A locked row's caption carries the price, the stock AND the level it wants.
     Held on one line at this width the ellipsis eats the level — the only part
     that explains why the field is dead — so here it wraps instead. */
  .srow .sub { white-space: normal; }
  .board { grid-template-columns: repeat(5, 1fr); }
}
