/* Maxwave web app. Mobile first, no external fonts or libraries. */
:root {
  --bg: #f5f1ea;
  --card: #ffffff;
  --ink: #221b15;
  --muted: #6b6158;
  --line: #e3dbcf;
  --brand: #7d1a1a;
  --brand-ink: #fff4e6;
  --accent: #e25a0c;
  --accent-dark: #b94506;
  --ok: #1c7a45;
  --ok-bg: #e4f4ea;
  --warn: #8f5200;
  --warn-bg: #fdf0d5;
  --err: #b3261e;
  --err-bg: #fbe6e4;
  --info: #1b5fa6;
  --info-bg: #e3eefb;
  --idle-bg: #efeae2;
  --radius: 12px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 "Noto Sans Devanagari", "Nirmala UI", "Mangal", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
body.app { padding-bottom: 76px; }
a { color: var(--brand); }
h1 { font-size: 1.45rem; margin: 0 0 .6rem; line-height: 1.3; }
h2 { font-size: 1.1rem; margin: 0 0 .7rem; line-height: 1.35; }
h2 small, label small, legend small, li small { font-weight: 400; color: var(--muted); font-size: .85rem; }
p { margin: 0 0 .7rem; }
code, .mono, pre { font-family: ui-monospace, "Cascadia Mono", Consolas, "Noto Sans Mono", monospace; font-size: .9rem; }
code { background: var(--idle-bg); padding: .05rem .35rem; border-radius: 5px; word-break: break-all; }
pre { background: var(--idle-bg); padding: .6rem; border-radius: 8px; overflow: auto; margin: .4rem 0 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* header + navigation */
.topbar {
  background: var(--brand); color: var(--brand-ink);
  display: flex; align-items: center; gap: 1rem; padding: .6rem 1rem;
  position: sticky; top: 0; z-index: 20;
}
.brand { color: var(--brand-ink); text-decoration: none; font-weight: 700; font-size: 1.15rem; letter-spacing: .01em; }
.brand span { font-weight: 400; opacity: .8; }
.logout { margin: 0 0 0 auto; }
.linkbtn { background: none; border: 1px solid rgba(255,255,255,.45); color: var(--brand-ink); border-radius: 8px; padding: .3rem .7rem; font: inherit; font-size: .9rem; cursor: pointer; }
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav a { text-align: center; padding: .85rem .2rem; text-decoration: none; color: var(--muted); font-size: .88rem; font-weight: 600; border-top: 3px solid transparent; }
.nav a.on { color: var(--brand); border-top-color: var(--accent); }

.page { max-width: 1060px; margin: 0 auto; padding: 1rem .8rem 2rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin: 0 0 1rem; }
.card.flush { padding: 0; overflow: hidden; }
.narrow { max-width: 430px; margin: 2.2rem auto; }
body.plain { padding: 0 .8rem; }
.headrow { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: .8rem; }
.headrow h1 { margin: 0; }
.grid2 { display: grid; gap: 0 1rem; }
.stack > .card { margin-bottom: 1rem; }

/* forms */
label { display: block; font-weight: 600; margin: 0 0 .8rem; }
label.check { font-weight: 400; display: flex; gap: .55rem; align-items: flex-start; }
label.check input { width: 1.25rem; height: 1.25rem; margin-top: .2rem; flex: none; }
input[type=text], input[type=password], input[type=number], input[type=url], select, textarea {
  display: block; width: 100%; margin-top: .3rem; padding: .65rem .7rem;
  border: 1px solid #cfc5b7; border-radius: 9px; background: #fff; color: var(--ink);
  font: inherit; font-weight: 400;
}
textarea { resize: vertical; line-height: 1.55; }
textarea.mono { font-size: .88rem; }
input[readonly] { background: var(--idle-bg); }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 3px solid #f0a35e; outline-offset: 1px;
}
fieldset { border: 1px solid var(--line); border-radius: 9px; padding: .7rem .8rem; margin: 0; }
legend { font-weight: 600; padding: 0 .3rem; }
.row2, .row3 { display: grid; gap: 0 .8rem; grid-template-columns: 1fr 1fr; }
.row3 { grid-template-columns: 1fr; }

.btn {
  display: inline-block; padding: .6rem 1rem; border-radius: 9px; border: 1px solid #c9bfb1;
  background: #fff; color: var(--ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; line-height: 1.3;
}
.btn:hover { background: #faf6f0; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #691414; }
.btn.danger { color: var(--err); border-color: #e3b1ad; }
.btn.danger.ghost { border-style: dashed; }
.btn.small { padding: .35rem .65rem; font-size: .88rem; }
.btn.block { display: block; width: 100%; }
.btn[disabled] { opacity: .55; cursor: default; }
.btnrow { display: flex; flex-wrap: wrap; gap: .5rem; margin: .5rem 0; }
.savebar { position: sticky; bottom: 76px; display: flex; gap: .6rem; background: var(--bg); padding: .6rem 0; z-index: 5; }
.danger-zone { margin: 1.5rem 0 0; }

/* Create card */
.create-btn {
  display: block; width: 100%; padding: 1.05rem; font-size: 1.5rem; font-weight: 800; letter-spacing: .02em;
  background: var(--accent); border: none; color: #fff; border-radius: 14px; box-shadow: 0 3px 0 var(--accent-dark);
}
.create-btn:hover { background: #d1510a; }
.create-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--accent-dark); }
.sum { font-weight: 600; margin: 0 0 .8rem; }
.sum.over { color: var(--warn); }

/* status bits */
.chip { display: inline-block; padding: .08rem .6rem; border-radius: 999px; font-size: .82rem; font-weight: 600; background: var(--idle-bg); color: var(--muted); white-space: nowrap; vertical-align: middle; }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.err { background: var(--err-bg); color: var(--err); }
.chip.info { background: var(--info-bg); color: var(--info); }
.tag { display: inline-block; font-size: .8rem; border: 1px solid var(--line); border-radius: 6px; padding: 0 .4rem; color: var(--muted); }
.flash { border-radius: 10px; padding: .7rem .9rem; margin: 0 0 .8rem; border: 1px solid; }
.flash.ok { background: var(--ok-bg); border-color: #b9dfc8; color: #12512e; }
.flash.warn { background: var(--warn-bg); border-color: #efd39a; color: #6b3d00; }
.flash.err { background: var(--err-bg); border-color: #efbab6; color: #7f1a14; }
.deskbar { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .9rem; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem .9rem; margin-bottom: 1rem; font-size: .93rem; }
.dot { display: inline-block; width: .7rem; height: .7rem; border-radius: 50%; background: #b9b0a4; margin-right: .4rem; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-bg); }
.dot.off { background: var(--err); }

/* job items */
.item { border-top: 1px solid var(--line); padding: .7rem 0; }
.item:first-child { border-top: none; }
.itemhead { display: flex; flex-wrap: wrap; gap: .3rem .7rem; align-items: center; }
.item p { margin: .3rem 0 0; }
.stagebar { display: grid; grid-template-columns: repeat(12, 1fr); gap: 3px; margin: .5rem 0 .2rem; }
.stagebar i { height: 8px; border-radius: 4px; background: var(--idle-bg); }
.stagebar i.past { background: var(--ok); }
.stagebar i.cur.info { background: var(--info); }
.stagebar i.cur.ok { background: var(--ok); }
.stagebar i.cur.warn { background: #e0a100; }
.stagebar i.cur.err { background: var(--err); }
.stagebar i.cur.idle { background: #b9b0a4; }
.jobhead { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .7rem; margin-bottom: .2rem; }
.queuerow { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; border-top: 1px solid var(--line); padding: .6rem 0; }
.queuerow:first-child { border-top: none; }

/* tables */
.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: .55rem .7rem; border-bottom: 1px solid var(--line); vertical-align: top; font-size: .93rem; }
th { color: var(--muted); font-size: .82rem; font-weight: 600; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.tools input { margin-top: 0; min-width: 9rem; }
table.tools td { padding: .3rem .3rem; }

/* misc */
details.sample { border: 1px solid var(--line); border-radius: 9px; padding: .5rem .8rem; margin-bottom: .6rem; }
details.sample summary { font-weight: 600; cursor: pointer; padding: .2rem 0; }
details.sample[open] summary { margin-bottom: .6rem; }
.catrow { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .6rem; }
.catrow h2 { margin-bottom: .2rem; }
.catrow p { margin: 0; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { border-top: 1px solid var(--line); padding: .5rem 0; font-size: .93rem; }
.timeline li:first-child { border-top: none; }
.timeline time { color: var(--muted); font-size: .82rem; margin-right: .4rem; font-variant-numeric: tabular-nums; }
.timeline .msg { display: block; margin-top: .15rem; overflow-wrap: anywhere; }
.timeline li.lv-error .msg { color: var(--err); }
.checks { list-style: none; margin: 0; padding: 0; }
.checks li { display: flex; gap: .6rem; padding: .5rem 0; border-top: 1px solid var(--line); }
.checks li:first-child { border-top: none; }
.checks li.fail { color: var(--err); font-weight: 600; }
.checks .mark { flex: none; width: 1.6rem; }
.tokenbox { border: 2px solid var(--accent); background: #fff8f1; }
.tokenrow { display: flex; flex-wrap: wrap; gap: .5rem; }
.tokenrow input { flex: 1 1 16rem; margin-top: 0; }
.pager { display: flex; align-items: center; gap: .8rem; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 88px; z-index: 50; background: #2b231c; color: #fff; padding: .65rem 1rem; border-radius: 10px; max-width: 92vw; box-shadow: 0 6px 20px rgba(0,0,0,.25); white-space: pre-line; }
.toast.err { background: var(--err); }

@media (max-width: 719px) {
  /* tables become stacked cards on phones */
  table.list thead, table.tools thead { display: none; }
  table.list tr, table.tools tr { display: block; padding: .6rem .8rem; border-bottom: 1px solid var(--line); }
  table.list td, table.tools td { display: flex; gap: .6rem; border: none; padding: .15rem 0; }
  table.list td[data-th]::before, table.tools td[data-th]::before { content: attr(data-th); flex: 0 0 7.2rem; color: var(--muted); font-size: .82rem; }
  table.tools td input { flex: 1; min-width: 0; }
}
@media (min-width: 720px) {
  body.app { padding-bottom: 0; }
  .nav { position: static; display: flex; gap: .2rem; background: none; border: none; padding: 0; }
  .nav a { color: var(--brand-ink); opacity: .8; padding: .35rem .8rem; border-radius: 8px; border: none; font-size: .95rem; }
  .nav a.on { color: #fff; opacity: 1; background: rgba(255,255,255,.16); }
  .page { padding: 1.4rem 1.2rem 3rem; }
  .grid2 { grid-template-columns: 1fr 1fr; }
  .row3 { grid-template-columns: repeat(3, 1fr); }
  .savebar { bottom: 0; }
  .toast { bottom: 24px; }
  .create-btn { max-width: 420px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
