/* Scopes and their rules (src/UI/scoped-rules.js): 区域 全局 → nation → city; 商路 全局 → begin nation → target → start city → route; both the 选区. */
/* the chooser: the header line and the scope choices (全局's expansion, or the 选区's items); the rules: the controls and 应用 / 重置 */
.scoped-rules { display: grid; gap: 8px; }
.scoped-rules-choices { display: grid; gap: 8px; }
.scoped-rules-params { display: grid; gap: 10px; }
.scoped-rules-choices[hidden],
.scoped-rules-params[hidden] { display: none; }

/* the header line in three fixed thirds (human 2026-11-02: "全局 is only 全局, still occupy 1/3, in the middle of the line.
   position of 全局 and xx规则 is fixed"): the title, 全局 with the triangle of its choices, then the right third: the 选区
   (while there is one) and 跳转 at the right end (human 2026-11-02: "跳转 is right to 全局, at the right most place"); the
   rest of the path on the line under it, a third each */
.scoped-rules-header { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: center; gap: 6px; }
.scoped-rules-header > .section-title { min-width: 0; margin: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.scoped-rules-tail { display: flex; align-items: center; justify-content: flex-end; gap: 6px; min-width: 0; }
.scoped-rules-tail > .scoped-rules-custom { flex: 1 1 auto; min-width: 0; }
/* the 选区 with 返回 and 进入 (the map fixed): three buttons in the third, tighter */
.scoped-rules-tail:has(> :nth-child(3)) { gap: 2px; }
.scoped-rules-tail:has(> :nth-child(3)) > button { padding: 0 2px; font-size: var(--font-small); }
.scoped-rules-jump {
  flex: none;
  height: 32px;
  padding: 0 8px;
  border: 1px solid #c8d0c9;
  border-radius: 3px;
  background: var(--paper-strong);
  color: var(--ink);
  font: inherit;
  font-size: var(--font-medium);
  white-space: nowrap;
  cursor: pointer;
}
.scoped-rules-jump:not(:disabled):hover { border-color: var(--teal); }
/* 返回: the map is fixed */
.scoped-rules-jump[aria-pressed="true"] { border-color: var(--teal); background: var(--teal); color: white; }
.scoped-rules-jump:disabled { cursor: not-allowed; opacity: 0.5; }
.scoped-rules-path.is-head { display: grid; min-width: 0; }
/* the chosen line has the same box as the choices under it (padding and a border, here clear), so a choice keeps its size
   when it moves up (human 2026-11-02: "the tag should not change size when selecting and move to the selected line") */
.scoped-rules-path.is-trail { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 6px; padding: 6px; border: 1px solid transparent; }
/* (twelfths: a nation or city a third, as in its list; a route half the line, as in its list of routes) */
.scoped-rules-path.is-trail > .scoped-rules-button { grid-column: span 4; }
.scoped-rules-path.is-trail > .scoped-rules-button.has-two-ends { grid-column: span 6; }
.scoped-rules-caret { margin-left: 6px; }

/* the next choices under the line, three a line (human: "1/3 width each in a line") */
.scoped-rules-expand {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  padding: 6px;
  border: 1px dashed var(--line);
  border-radius: 3px;
  background: var(--paper);
}
.scoped-rules-button {
  min-width: 0;
  height: 32px;
  padding: 0 6px;
  overflow: hidden;
  border: 1px solid #c8d0c9;
  border-left: 4px solid var(--scope-color, #c8d0c9);
  border-radius: 3px;
  background: var(--paper-strong);
  color: var(--ink);
  font: inherit;
  font-size: var(--font-medium);
  white-space: nowrap;
  text-overflow: ellipsis;
  cursor: pointer;
}
/* a chosen level on the path is green: 全局 while its choices are open, every button of the line under it; 全局 closed has
   the normal style of the choices (human: "click on 全局 should make it background color from green to normal just as
   nations") */
/* a light green (human: "the selected color should not be to deep"); the colour bars stay */
.scoped-rules-path .scoped-rules-button[aria-pressed="true"] { border-top-color: #9cc5ae; border-bottom-color: #9cc5ae; background: #e4f0e8; }
.scoped-rules-path .scoped-rules-button[aria-pressed="true"]:not(.has-two-ends) { border-right-color: #9cc5ae; }
/* the 选区 button (the third of the header line), green when it is the scope */
.scoped-rules-tail > .scoped-rules-custom[aria-pressed="true"] { border-color: #9cc5ae; background: #e4f0e8; }

/* the 选区's items: its cities under their nations (the nation's name, then its cities three a line), its routes two a line;
   each a button with × that removes it from the 选区 */
.scoped-rules-group { display: grid; gap: 4px; }
.scoped-rules-group-title { padding-left: 6px; border-left: 4px solid var(--scope-color, #c8d0c9); color: var(--muted); font-size: var(--font-small); }
.scoped-rules-removable { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.scoped-rules-removable > .scoped-rules-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.scoped-rules-remove { flex: none; color: var(--muted); }
.scoped-rules-removable:hover .scoped-rules-remove { color: #c0392b; }
.scoped-rules-expand.is-removable-routes { grid-template-columns: repeat(2, minmax(0, 1fr)); }
/* a route: its two cities' colours, left and right */
.scoped-rules-button.has-two-ends { border-right: 4px solid var(--scope-color2, #c8d0c9); }

/* a start city's routes, two a line (human 2026-11-02: "No direction bar anymore, select a original city will provide related
   routes only"); a route chosen lists nothing under it */
.scoped-rules-expand.is-routes { grid-template-columns: repeat(2, minmax(0, 1fr)); }

/* 应用 | 重置 under the controls */
.scoped-rules-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.scoped-rules-actions button {
  min-width: 0;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--paper-strong);
  color: var(--ink);
  font: inherit;
  font-size: var(--font-medium);
  cursor: pointer;
}
.scoped-rules-actions button[data-scoped-apply]:not(:disabled) { border-color: #b78b3e; color: #b78b3e; }
.scoped-rules-actions button:disabled { cursor: default; opacity: 0.55; }

/* a route scope's rules (human 2026-11-02: "tariff should have both side: 鹰源州→碧阳湾 碧阳湾→鹰源州 / 出口税 进口税 移入额度
   移出额度"): a column per direction, its name between its two sides' colours, a row per setting; an input per cell, gold
   while a draft, red when a quota is not a whole number or a percentage */
.scoped-route-table { width: 100%; table-layout: fixed; }
.scoped-route-table th[scope="row"] { width: 30%; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: help; }
.scoped-route-table.is-single th[scope="row"] { width: 50%; }
.scoped-route-table thead th { white-space: normal; vertical-align: bottom; }
/* (a long name breaks after its arrow) */
.scoped-route-direction { display: block; padding: 0 4px; white-space: normal; word-break: keep-all; overflow-wrap: anywhere; }
.scoped-route-direction.has-bars { border-left: 4px solid var(--route-a, #c8d0c9); border-right: 4px solid var(--route-b, #c8d0c9); }
.scoped-route-table td { padding: 4px 6px; }
.scoped-route-table td > input { display: block; width: 100%; min-width: 0; height: 32px; box-sizing: border-box; font-size: var(--font-medium); }
:is(.scoped-route-table td, .route-global-policy-control) > input.is-invalid { border-color: #c0392b !important; box-shadow: 0 0 0 1px #c0392b !important; color: #c0392b !important; }
.route-global-policy-control > span[title] { cursor: help; }
/* the 跨城转职 switch under it, a draft gold */
.scoped-route-cross > span:first-child { cursor: help; }
.global-policy-toggle.scoped-route-cross.is-draft .switch-pair button[aria-pressed="true"] { border-color: #b78b3e; background: #b78b3e; }
