:root {
  --bg: #f7f5f1;
  --panel: #ffffff;
  --fg: #221d16;
  --mut: #6f6558;
  --line: #e5ded2;
  --acc: #c2571a;
  --acc-soft: #fdf1e7;
  --danger: #b3261e;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(60, 45, 25, .06), 0 8px 24px rgba(60, 45, 25, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14110c; --panel: #1c1813; --fg: #f2ece1; --mut: #a1968a;
    --line: #2f2820; --acc: #f38020; --acc-soft: #2a1d10; --danger: #ff6b60;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "PingFang TC", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

/* ---------- login ---------- */
#login { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 100; }
#login .card { background: var(--panel); padding: 32px; border-radius: 18px; box-shadow: var(--shadow); width: min(360px, 92vw); border: 1px solid var(--line); }
#login h1 { margin: 0 0 4px; font-size: 20px; }
#login p { margin: 0 0 20px; color: var(--mut); font-size: 13px; }
#login input { width: 100%; padding: 11px 13px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); }
#login button { width: 100%; margin-top: 12px; padding: 11px; border: 0; border-radius: 9px; background: var(--acc); color: #fff; font-weight: 600; }
#login .err { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* ---------- shell ---------- */
header {
  position: sticky; top: 0; z-index: 20; background: var(--panel);
  border-bottom: 1px solid var(--line); padding: 10px 16px;
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
}
.brand { font-weight: 700; letter-spacing: .2px; }
.brand span { color: var(--acc); }
/* The tab row absorbs the spare width and scrolls sideways rather than wrapping, so the action
   buttons stay together on one line however many views exist. */
nav.tabs { display: flex; gap: 2px; margin-left: 4px; flex: 1 1 auto; min-width: 0;
  overflow-x: auto; scrollbar-width: none; }
nav.tabs::-webkit-scrollbar { display: none; }
nav.tabs button { white-space: nowrap; flex: 0 0 auto; }
nav.tabs button {
  background: none; border: 0; padding: 7px 12px; border-radius: 8px; color: var(--mut); font-weight: 500;
}
nav.tabs button.on { background: var(--acc-soft); color: var(--acc); }
.spacer { flex: 1; }
.tool {
  border: 1px solid var(--line); background: var(--panel); padding: 7px 12px;
  border-radius: 8px; display: inline-flex; gap: 6px; align-items: center; flex: 0 0 auto;
}
.tool:hover { border-color: var(--acc); color: var(--acc); }
.tool.primary { background: var(--acc); border-color: var(--acc); color: #fff; font-weight: 600; }
.tool.primary:hover { filter: brightness(1.07); color: #fff; }
.tool[disabled] { opacity: .45; pointer-events: none; }
#search { border: 1px solid var(--line); background: var(--bg); padding: 7px 11px; border-radius: 8px; width: 180px; flex: 0 0 auto; }

/* ---------- crumbs ---------- */
.crumbs { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; padding: 12px 16px 4px; color: var(--mut); }
.crumbs a { color: var(--mut); text-decoration: none; padding: 3px 7px; border-radius: 6px; }
.crumbs a:hover { background: var(--acc-soft); color: var(--acc); }
.crumbs .sep { opacity: .5; }
.crumbs .here { color: var(--fg); font-weight: 600; padding: 3px 7px; }

/* ---------- content ---------- */
main { padding: 8px 16px 40px; }
.dropzone { border: 2px dashed transparent; border-radius: var(--radius); transition: .15s; }
.dropzone.over { border-color: var(--acc); background: var(--acc-soft); }
.empty { text-align: center; color: var(--mut); padding: 64px 20px; }
.empty .big { font-size: 40px; opacity: .5; display: block; margin-bottom: 8px; }

/* grid */
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); }
.tile {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; display: flex; flex-direction: column; gap: 8px; box-shadow: var(--shadow);
  position: relative; min-height: 132px;
}
.tile:hover { border-color: var(--acc); }
.tile .ico { font-size: 30px; line-height: 1; height: 62px; display: grid; place-items: center; border-radius: 8px; background: var(--acc-soft); overflow: hidden; }
.tile .ico img { width: 100%; height: 100%; object-fit: cover; }
.tile .nm { font-size: 13px; font-weight: 500; word-break: break-all; line-height: 1.35; flex: 1; }
.tile .sub { font-size: 11px; color: var(--mut); }
.tile .acts { display: flex; gap: 4px; position: absolute; top: 8px; right: 8px; opacity: 0; transition: .12s; }
.tile:hover .acts { opacity: 1; }
.tile .acts button { border: 1px solid var(--line); background: var(--panel); border-radius: 6px; width: 26px; height: 26px; display: grid; place-items: center; font-size: 12px; }
.tile .acts button:hover { border-color: var(--acc); color: var(--acc); }
.star { position: absolute; top: 8px; left: 8px; font-size: 13px; }
.tile .lockbadge { position: absolute; top: 26px; left: 8px; font-size: 13px; }
.calwrap { max-width: 900px; }
.calhead { font-size: 16px; font-weight: 700; margin-bottom: 10px; }
.caldow { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; font-size: 11px; color: var(--mut); text-align: center; margin-bottom: 6px; }
.calgrid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 18px; }
.calgrid .cell { min-height: 62px; border: 1px solid var(--line); border-radius: 9px; padding: 5px 6px; font-size: 11px; background: var(--panel); overflow: hidden; }
.calgrid .cell.blank { border: 0; background: transparent; }
.calgrid .cell.today { border-color: var(--acc); box-shadow: 0 0 0 1px var(--acc) inset; }
.calgrid .cell b { display: block; font-size: 12px; margin-bottom: 3px; }
.calgrid .ev { display: block; background: var(--acc-soft); color: var(--acc); border-radius: 5px; padding: 1px 4px; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.calgrid .more { color: var(--mut); }
.addrow { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.addrow input { padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: inherit; }
.addrow button { border: 1px solid var(--acc); background: var(--acc); color: #fff; border-radius: 8px; padding: 9px 16px; font-weight: 600; cursor: pointer; }
.calwrap table.list td, .calwrap table.list th { font-size: 13px; }
.askbox { max-width: 780px; }
.askbox textarea { width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: inherit; font: inherit; resize: vertical; }
.askrow { display: flex; align-items: center; gap: 12px; margin: 10px 0 18px; }
.askrow button.go { border: 0; background: var(--acc); color: #fff; font-weight: 600; border-radius: 9px; padding: 10px 20px; cursor: pointer; }
.askrow button.go:disabled { opacity: .6; pointer-events: none; }
.askrow .meta { font-size: 12px; color: var(--mut); }
#askA .ans { white-space: pre-wrap; line-height: 1.75; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; }
#askA .srcs { margin-top: 10px; font-size: 12px; color: var(--mut); }
.cite { display: inline-block; background: var(--acc-soft); color: var(--acc); border-radius: 999px; padding: 3px 10px; margin: 4px 6px 0 0; font-weight: 600; }
.cite b { opacity: .7; font-weight: 500; }
/* Flex row, not absolute positioning: `#login button` sets width:100% for the submit
   button, and an absolutely-positioned child inherits it, which covered the input. */
#login .pwrow { display: flex; gap: 8px; align-items: center; }
#login .pwrow input { flex: 1 1 auto; width: auto; min-width: 0; }
#login .pwrow button { flex: 0 0 auto; width: auto; margin-top: 0; padding: 9px 12px; border: 1px solid var(--line); background: var(--bg); color: var(--mut); font-size: 12px; font-weight: 600; border-radius: 9px; cursor: pointer; white-space: nowrap; }
#login .pwrow button.on { border-color: var(--acc); color: var(--acc); }
#login .pwinfo { font-size: 11px; color: var(--mut); margin: 2px 0 10px; min-height: 14px; }
/* Breathing room between the account field and the password row. */
#login form > input { margin-bottom: 14px; }
#login .pwinfo.warn { color: var(--danger); font-weight: 600; }
#login details { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
#login details summary { font-size: 12px; color: var(--mut); cursor: pointer; }
#login details pre { margin: 8px 0 0; font: 11px/1.55 ui-monospace, "Cascadia Mono", Consolas, monospace; color: var(--mut); white-space: pre-wrap; word-break: break-all; max-height: 46vh; overflow: auto; }
.usersadd { margin-bottom: 12px; }
.usersadd button { border: 1px solid var(--line); background: var(--panel); border-radius: 9px; padding: 8px 14px; font-weight: 600; }
.usersadd button:hover { border-color: var(--acc); color: var(--acc); }
.snip { font-size: 11px; color: var(--mut); line-height: 1.4; margin-top: 2px; }
.tile .snip { max-height: 3em; overflow: hidden; }
.snip mark { background: var(--acc-soft); color: var(--acc); font-weight: 600; padding: 0 1px; border-radius: 3px; }
table.list .snip { margin-left: 24px; }
#modal ul.files { list-style: none; margin: 0 0 4px; padding: 0; max-height: 46vh; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
#modal ul.files li { display: flex; justify-content: space-between; gap: 10px; align-items: center; padding: 9px 12px; border-bottom: 1px solid var(--line); font-size: 13px; }
#modal ul.files li:last-child { border-bottom: 0; }
#modal ul.files button { border: 1px solid var(--line); background: var(--panel); border-radius: 7px; padding: 3px 9px; font-size: 12px; margin-left: 4px; }
#modal ul.files button:hover { border-color: var(--acc); color: var(--acc); }

/* list */
table.list { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.list th { text-align: left; font-size: 12px; color: var(--mut); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--bg); }
table.list td { padding: 9px 12px; border-bottom: 1px solid var(--line); font-size: 13px; }
table.list tr:last-child td { border-bottom: 0; }
table.list tr:hover td { background: var(--acc-soft); }
table.list .nm { cursor: pointer; display: flex; gap: 8px; align-items: center; }
table.list .nm .ic { font-size: 16px; }
table.list td.r { text-align: right; white-space: nowrap; }
table.list td.r button { border: 1px solid var(--line); background: var(--panel); border-radius: 6px; padding: 3px 8px; font-size: 12px; margin-left: 3px; }
table.list td.r button:hover { border-color: var(--acc); color: var(--acc); }

/* ---------- transfers ---------- */
#xfer { position: fixed; bottom: 16px; right: 16px; width: min(340px, 92vw); z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.xf { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; box-shadow: var(--shadow); font-size: 12px; }
.xf .t { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.xf .bar { height: 4px; background: var(--line); border-radius: 3px; overflow: hidden; }
.xf .bar i { display: block; height: 100%; background: var(--acc); width: 0; transition: width .15s; }
.xf.done .bar i { background: #2e7d32; }
.xf.err .bar i { background: var(--danger); }

/* ---------- toast ---------- */
#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 24px; z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.tst { background: #221d16; color: #f7f5f1; padding: 10px 16px; border-radius: 10px; font-size: 13px; box-shadow: var(--shadow); }
.tst.err { background: var(--danger); color: #fff; }
@media (prefers-color-scheme: dark) { .tst { background: #2f2820; color: var(--fg); } }

/* ---------- modal ---------- */
#modal { position: fixed; inset: 0; background: rgba(20,15,10,.45); display: grid; place-items: center; z-index: 90; }
#modal .box { background: var(--panel); border-radius: 14px; padding: 22px; width: min(400px, 92vw); box-shadow: var(--shadow); border: 1px solid var(--line); }
#modal h3 { margin: 0 0 6px; font-size: 16px; }
#modal p { margin: 0 0 14px; color: var(--mut); font-size: 13px; }
#modal input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
#modal .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
#modal button { border: 1px solid var(--line); background: var(--panel); padding: 8px 14px; border-radius: 8px; }
#modal button.go { background: var(--acc); border-color: var(--acc); color: #fff; font-weight: 600; }
#modal button.bad { background: var(--danger); border-color: var(--danger); color: #fff; }
#modal label.fld { display: block; font-size: 12px; color: var(--mut); margin: 0 0 10px; }
#modal label.fld select, #modal label.fld input { width: 100%; margin-top: 4px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: inherit; }
#modal p.lbl { margin: 4px 0 6px; font-size: 12px; color: var(--mut); }
.linkrow { display: flex; gap: 6px; }
.linkrow input { flex: 1; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: inherit; font-size: 12px; }
.linkrow button { border: 1px solid var(--acc); background: var(--acc); color: #fff; border-radius: 8px; padding: 0 14px; font-weight: 600; }
#modal button.go:disabled { opacity: .6; pointer-events: none; }

/* ---------- preview ---------- */
#preview { position: fixed; inset: 0; background: rgba(10,8,5,.86); z-index: 95; display: grid; place-items: center; }
#preview img, #preview video, #preview iframe { max-width: 94vw; max-height: 88vh; border-radius: 8px; background: #fff; }
#preview .close { position: absolute; top: 18px; right: 22px; background: none; border: 0; color: #fff; font-size: 30px; }
.badge { display: inline-block; font-size: 10px; padding: 1px 6px; border-radius: 5px; background: var(--acc-soft); color: var(--acc); font-weight: 600; margin-left: 6px; }
footer.hint { padding: 0 16px 24px; color: var(--mut); font-size: 12px; }

/* ---------- in-page editor (GridCraft bridge) ---------- */
#editor { position: fixed; inset: 0; background: var(--bg); z-index: 70; display: flex; flex-direction: column; }
#editor .bar { display: flex; gap: 10px; align-items: center; padding: 9px 14px; border-bottom: 1px solid var(--line); background: var(--panel); }
#editor .fname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 42vw; }
#editor .stat { font-size: 12px; color: var(--mut); white-space: nowrap; }
#editor .stat.ok { color: #2e7d32; }
#editor .stat.warn { color: var(--acc); font-weight: 600; }
#editor .stat.bad { color: var(--danger); }
#editor iframe { flex: 1; border: 0; width: 100%; background: #fff; }

/* chat view (the "AI 問答" tab): a real conversation, not a single-shot answer box */
.chatbox { display: flex; flex-direction: column; gap: 12px; height: calc(100vh - 190px); }
.chatlog { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 4px 2px; }
.chatlog .msg { max-width: 78%; border-radius: 14px; padding: 10px 14px; border: 1px solid var(--line); background: var(--panel); }
.chatlog .msg.user { align-self: flex-end; background: var(--acc); border-color: transparent; color: #fff; }
.chatlog .msg.assistant { align-self: flex-start; }
.chatlog .who { font-size: 11px; opacity: .65; margin-bottom: 5px; letter-spacing: .03em; }
.chatlog .ans { white-space: pre-wrap; line-height: 1.75; }
.chatlog .srcs { margin-top: 9px; font-size: 12px; opacity: .72; }
.chatrow { display: flex; gap: 10px; align-items: flex-end; }
.chatrow textarea { flex: 1; resize: vertical; min-height: 52px; }
.chatrow .go { flex: 0 0 auto; }
.chatbox .askrow { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.chatbox .ghost { background: transparent; border: 1px solid var(--line); color: var(--mut); padding: 6px 10px; border-radius: 8px; font-size: 12px; cursor: pointer; }

/* users view: the add-user form */
.usersadd { margin-top: 14px; }
.addform { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.addform input, .addform select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: inherit; }
.addform input#nuName { width: 170px; }
.addform input#nuDisplay { width: 200px; }
.addform input#nuPass { width: 220px; }
.addform button { padding: 8px 14px; border-radius: 8px; border: none; background: var(--acc); color: #fff; cursor: pointer; }

/* the program bar: one button per ArtCraft app, so a program can be launched from the drive
   instead of only by opening a file */
nav.programs { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 18px;
  border-bottom: 1px solid var(--line); background: var(--panel); }
nav.programs .plabel { font-size: 12px; color: var(--mut); margin-right: 4px; }
nav.programs button { display: inline-flex; align-items: center; gap: 6px; padding: 7px 13px;
  border: 1px solid var(--line); border-radius: 999px; background: transparent; color: inherit;
  font-size: 13px; cursor: pointer; }
nav.programs button:hover { border-color: var(--acc); color: var(--acc); }
nav.programs button .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--acc); opacity: .75; }
/* program picker */
.picklist { max-height: 46vh; overflow-y: auto; margin: 6px 0 10px; border: 1px solid var(--line); border-radius: 10px; }
.picklist .pr { display: flex; align-items: center; gap: 10px; padding: 9px 12px; cursor: pointer; border-bottom: 1px solid var(--line); }
.picklist .pr:last-child { border-bottom: none; }
.picklist .pr:hover { background: rgba(0,0,0,.04); }
.picklist .pr .nm2 { flex: 1; }
.picklist .pr .sz2 { font-size: 12px; color: var(--mut); }
.picklist .empty { padding: 16px; text-align: center; color: var(--mut); font-size: 13px; }

/* MCP tab */
.mcpwrap h3 { margin: 22px 0 8px; font-size: 15px; }
.mcpcards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; margin-bottom: 8px; }
.mcpcard { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--panel); }
.mcpcard .k { font-size: 11px; color: var(--mut); margin-bottom: 5px; letter-spacing: .04em; }
.mcpcard code { font-size: 12px; word-break: break-all; }
.mcpnote { font-size: 12.5px; color: var(--mut); margin: 4px 0 10px; }
.mcprow { display: flex; gap: 8px; margin-bottom: 10px; }
.mcprow button { padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: transparent; color: inherit; cursor: pointer; }
.mcprow button.go { background: var(--acc); border-color: transparent; color: #fff; }
.mcpjson { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px;
  font-size: 12px; line-height: 1.6; white-space: pre; overflow-x: auto; margin: 0 0 6px; }
.mcptools { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 8px; }
.mcptool { border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; background: var(--panel); }
.mcptool code { display: block; font-size: 12.5px; margin-bottom: 3px; }
.mcptool span { font-size: 12px; color: var(--mut); }

/* internal sharing dialog */
.tsrow { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 10px 0; }
.tsrow select, .tsrow input { padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: inherit; }
.tsrow input { flex: 1 1 160px; min-width: 130px; }
.tsrow button { padding: 7px 12px; border-radius: 8px; border: 1px solid var(--line); background: transparent; color: inherit; cursor: pointer; }
.tslist { max-height: 30vh; overflow-y: auto; margin-bottom: 10px; }
.tsitem { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 11px; border: 1px solid var(--line); border-radius: 9px; margin-bottom: 6px; font-size: 13px; }
.tsitem button { border: 1px solid var(--line); background: transparent; color: var(--mut); border-radius: 7px; padding: 4px 9px; cursor: pointer; }

/* embedded quotation system */
.embedwrap { display: flex; flex-direction: column; height: calc(100vh - 190px); gap: 8px; }
.embedbar { display: flex; align-items: center; gap: 8px; }
.embedbar .etitle { font-weight: 600; }
.embedbar a.tool { text-decoration: none; }
.embedframe { flex: 1; width: 100%; border: 1px solid var(--line); border-radius: 10px; background: #fff; }

/* local WASM quotation form */
.box.wide { width: min(680px, 92vw); }
.qf2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin: 10px 0; }
.qf2 label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--mut); }
.qf2 input, .qf2 select { padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: inherit; }
#qwItems, #qwNotes { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; }
