:root {
  --bg: #eef0f5; --card: #fff; --panel: #f7f8fb; --fg: #1a2233; --mut: #6a7587; --line: #dde1ea;
  --acc: #3563e0; --acc-soft: #e6edff; --accfg: #fff;
  --req: #c2571a; --del: #17803f;
  --gold: #8a6100; --gold-bg: #fff2cc;
  --chg: #fff7dc; --chgline: #e8b931;
  --danger: #c4311f; --danger-bg: #fde8e5;
  --shadow: 0 1px 2px rgba(20, 30, 60, .06), 0 4px 14px rgba(20, 30, 60, .05);
  --r: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1218; --card: #181d27; --panel: #131822; --fg: #e8ebf2; --mut: #8d97aa; --line: #2a3140;
    --acc: #7fa2f5; --acc-soft: #1d2a4a; --accfg: #0d1320;
    --req: #f0975c; --del: #5fcf8f;
    --gold: #f1c75a; --gold-bg: #3a3017;
    --chg: #2b2613; --chgline: #8a6f1c;
    --danger: #ff8a7a; --danger-bg: #3a1f1f; --shadow: none;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 14px/1.4 system-ui, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- topo ---------- */
.top {
  position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
  padding: 10px 24px; display: flex; gap: 10px 16px; align-items: center; flex-wrap: wrap;
}
.title h1 { margin: 0; font-size: 19px; letter-spacing: -.01em; }
.title h1 span { color: var(--mut); font-weight: 400; font-size: 14px; letter-spacing: 0; }
.title p { margin: 1px 0 0; color: var(--mut); font-size: 12px; }
#q {
  flex: 1 1 260px; min-width: 200px; max-width: 440px; padding: 9px 12px 9px 34px;
  border: 1px solid var(--line); border-radius: 10px; color: var(--fg);
  background: var(--card) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%238d97aa' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='7' cy='7' r='5'/%3E%3Cpath d='M11 11l3.5 3.5'/%3E%3C/svg%3E") no-repeat 11px 50%;
}
#q:focus, .qty:focus, .gold:focus, #pkq:focus { outline: 2px solid var(--acc); outline-offset: 0; }
.tabs { display: inline-flex; padding: 3px; gap: 2px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
.tabs button { padding: 5px 14px; border: 0; border-radius: 7px; background: none; color: var(--mut); }
.tabs button.on { background: var(--acc); color: var(--accfg); font-weight: 600; }
.actions { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.actions button { padding: 7px 13px; border: 1px solid var(--line); border-radius: 9px; background: var(--card); }
.actions button:hover:not(:disabled) { border-color: var(--acc); }
.actions .primary { background: var(--acc); border-color: var(--acc); color: var(--accfg); font-weight: 600; }
.actions .ghost { color: var(--danger); }
.actions button:disabled { opacity: .4; cursor: not-allowed; }

.hint {
  margin: 14px auto 0; max-width: 1500px; padding: 10px 14px; color: var(--mut); font-size: 13px;
  background: var(--acc-soft); border-radius: 10px; width: calc(100% - 48px);
}
.hint b { color: var(--fg); font-weight: 600; }

/* ---------- cartões de missão ---------- */
.list { max-width: 1500px; margin: 0 auto; padding: 14px 24px 60px; display: grid; gap: 14px; }
.nothing { text-align: center; color: var(--mut); padding: 40px; }
.mission { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; }
.mission.chg { border-color: var(--chgline); box-shadow: 0 0 0 1px var(--chgline), var(--shadow); }
.m-head { display: flex; align-items: center; gap: 10px; padding: 9px 14px; border-bottom: 1px solid var(--line); }
.mission.chg .m-head { background: var(--chg); }
.badge { font: 700 13px ui-monospace, Consolas, monospace; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 2px 9px; }
.state { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--gold); background: var(--gold-bg); border-radius: 99px; padding: 2px 10px; }
.mini { margin-left: auto; border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 3px 10px; font-size: 12px; color: var(--mut); }
.mini:hover { color: var(--fg); border-color: var(--acc); }

.m-body { display: grid; grid-template-columns: 1fr 1fr; }
.panel { padding: 12px 14px 14px; min-width: 0; }
.panel.old { background: var(--panel); border-right: 1px solid var(--line); }
.panel h3 { margin: 0 0 8px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--mut); }
.panel.new h3 { color: var(--acc); }
.panel h3 small { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--mut); margin-left: 4px; }

.cols { display: grid; grid-template-columns: minmax(0, 1fr) 22px minmax(0, 1fr); gap: 6px; align-items: start; }
.mid { align-self: center; text-align: center; color: var(--mut); font-size: 18px; }
.col h4 { margin: 0 0 4px; font-size: 11px; font-weight: 600; color: var(--mut); text-transform: uppercase; letter-spacing: .05em; }
.none { color: var(--mut); padding: 6px 0; }

.it { display: flex; align-items: center; gap: 9px; padding: 4px 0; }
.ic { width: 38px; height: 38px; border-radius: 8px; border: 1px solid var(--line); background: #000; flex: none; object-fit: cover; }
.ic.no { display: inline-flex; align-items: center; justify-content: center; color: var(--mut); background: var(--panel); }
.nm { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.nm b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.id { color: var(--mut); font-size: 11.5px; }
.ef { color: var(--acc); font-size: 11.5px; background: none; border: 0; padding: 0 0 0 4px; }

.pill { display: inline-flex; align-items: center; gap: 5px; border-radius: 99px; padding: 1px 9px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.q { font-size: 13px; font-weight: 700; background: var(--card); border: 1px solid var(--line); }
.req .pill.q { color: var(--req); } .del .pill.q { color: var(--del); }
.pill.gold { background: var(--gold-bg); color: var(--gold); padding: 3px 11px; }
.pill.none { color: var(--mut); border: 1px dashed var(--line); padding: 2px 10px; font-weight: 400; }
.pill.rw { color: var(--mut); border: 1px solid var(--line); font-weight: 400; }
.pill .ic { width: 18px; height: 18px; border-radius: 4px; }
.foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--line); }

/* ---------- edição ---------- */
.edit .ic { cursor: pointer; transition: transform .1s; }
.edit .ic:hover { outline: 2px solid var(--acc); transform: scale(1.05); }
.qty, .gold { padding: 5px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--fg); font-weight: 700; text-align: right; }
.qty { width: 78px; flex: none; }
.gold { width: 170px; }
.goldf { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; color: var(--gold); }
.edit .req .qty { color: var(--req); } .edit .del .qty { color: var(--del); }
.x { border: 0; background: none; color: var(--mut); font-size: 15px; padding: 3px 7px; border-radius: 6px; opacity: .5; }
.it:hover .x { opacity: 1; }
.x:hover { color: var(--danger); background: var(--danger-bg); }
.add { margin-top: 6px; border: 1px dashed var(--acc); background: none; color: var(--acc); border-radius: 8px; padding: 4px 12px; font-size: 12.5px; }
.add:hover { background: var(--acc-soft); }

/* ---------- seletor de itens ---------- */
dialog { width: min(580px, 94vw); max-height: 84vh; padding: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--card); color: var(--fg); box-shadow: 0 20px 60px rgba(0, 0, 0, .35); }
dialog::backdrop { background: rgba(8, 10, 16, .6); backdrop-filter: blur(2px); }
.pk-head { display: flex; gap: 8px; padding: 12px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--card); margin: 0; }
.pk-head input { flex: 1; padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); color: var(--fg); }
.pk-head button { padding: 6px 14px; border: 1px solid var(--line); border-radius: 9px; background: var(--card); }
.pk-res { max-height: 58vh; overflow: auto; padding: 6px; }
.pk-res button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 5px 8px; border: 0; background: none; text-align: left; border-radius: 8px; }
.pk-res button:hover, .pk-res button:focus { background: var(--acc-soft); outline: none; }
.pk-info { margin: 0; padding: 8px 14px 12px; color: var(--mut); font-size: 12px; }

#toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(8px); background: var(--fg); color: var(--bg); padding: 9px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 20; }
#toast.on { opacity: 1; transform: translateX(-50%); }

@media (max-width: 1100px) {
  .m-body { grid-template-columns: 1fr; }
  .panel.old { border-right: 0; border-bottom: 1px solid var(--line); }
}
@media (max-width: 640px) {
  .top { padding: 10px 14px; }
  .hint { width: calc(100% - 28px); }
  .list { padding: 12px 14px 50px; }
  .cols { grid-template-columns: 1fr; }
  .mid { transform: rotate(90deg); }
  .actions { margin-left: 0; }
}

.oldm + .oldm { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.ref { font: 700 12px ui-monospace, Consolas, monospace; color: var(--mut); margin-bottom: 6px; }
