:root {
  --ground: #F3F1EA; --surface: #FFFFFF; --ink: #15171C; --muted: #61656D;
  --line: #E3E0D6; --line2: #CFCBBE; --side: #14171C; --head: #FAF9F4;
  --accent: #0D6B5F; --accent-dark: #094C43; --accent-bg: #E1EFEB;
  --ok: #1D6B43; --ok-bg: #E3F1E8; --off: #585C64; --off-bg: #ECEAE3;
  --err: #A82F25; --err-bg: #F8E6E3; --warn: #7D5200; --warn-bg: #F7EBD0;
  --serif: 'Instrument Serif', Georgia, serif;
  --sans: 'Instrument Sans', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--ground); color: var(--ink); font-family: var(--sans); font-size: 14px; line-height: 1.4; }
a { color: var(--accent); } a:hover { color: var(--accent-dark); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* shell */
.shell { display: flex; min-height: 100vh; }
.side { width: 232px; flex-shrink: 0; background: var(--side); padding: 20px 12px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 12px 8px; color: #fff; text-decoration: none; }
.brand-mark { width: 32px; height: 32px; border-radius: 8px; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; }
.brand-name { font-family: var(--serif); font-size: 22px; }
.side-label { padding: 0 12px; margin: 20px 0 6px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: #8B8F98; }
.nav-item { display: flex; align-items: center; gap: 12px; height: 40px; padding: 0 12px; border-radius: 8px; color: #BDC0C8; text-decoration: none; }
.nav-item:hover { color: #fff; background: #1E232B; }
.nav-item[aria-current="page"] { background: #252B34; color: #fff; font-weight: 500; }
.side-foot { margin-top: auto; border-top: 1px solid #272C34; padding: 16px 12px 4px; display: flex; flex-direction: column; gap: 12px; }
.who { display: flex; align-items: center; gap: 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: #2C333D; color: #fff; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; text-transform: uppercase; }
.who-name { color: #fff; font-weight: 500; } .who-role { color: #A2A6AF; font-size: 12px; }
.side-links { display: flex; gap: 16px; }
.link-btn { background: none; border: 0; padding: 0; color: #BDC0C8; font: inherit; font-size: 13px; cursor: pointer; text-decoration: none; }
.link-btn:hover { color: #fff; }
main { flex-grow: 1; min-width: 0; padding: 32px; display: flex; flex-direction: column; gap: 24px; }

/* header */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; flex-wrap: wrap; }
h1 { margin: 0; font-family: var(--serif); font-weight: 400; font-size: 40px; line-height: 1.1; letter-spacing: -.01em; }
h2 { margin: 0; font-family: var(--serif); font-weight: 400; font-size: 26px; }
.sub { margin: 8px 0 0; color: var(--muted); }
.actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

/* controls */
.btn { height: 40px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--line2); background: var(--surface); color: var(--ink); font: inherit; font-weight: 500; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--muted); color: var(--ink); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); color: #fff; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-text { height: 32px; padding: 0 8px; border: 0; background: none; color: var(--accent); font: inherit; font-size: 13px; font-weight: 500; cursor: pointer; }
.btn-text.danger { color: var(--err); }
.input, select.input { height: 40px; width: 100%; border: 1px solid var(--line2); border-radius: 8px; padding: 0 12px; background: var(--surface); color: var(--ink); font: inherit; }
select.input { padding: 0 10px; width: auto; }
.input.mono { font-family: var(--mono); font-size: 13px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 500; }
.hint { font-size: 12px; color: var(--muted); }
.search { position: relative; flex-grow: 1; max-width: 360px; }
.search svg { position: absolute; left: 12px; top: 11px; color: var(--muted); }
.search .input { padding-left: 38px; }
.filters { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

/* cards, stats */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.card.pad { padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 16px; }
.stat { padding: 16px 20px; display: flex; flex-direction: column; gap: 4px; }
.stat span { font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.stat strong { font-family: var(--serif); font-weight: 400; font-size: 40px; line-height: 1.1; font-variant-numeric: tabular-nums; }

/* pills */
.pill { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--ok-bg); color: var(--ok); } .pill.off { background: var(--off-bg); color: var(--off); }
.pill.err { background: var(--err-bg); color: var(--err); } .pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.accent { background: var(--accent-bg); color: var(--accent); }
.chip { display: inline-flex; align-items: center; height: 24px; padding: 0 8px; border-radius: 6px; background: var(--head); border: 1px solid var(--line); font-family: var(--mono); font-size: 12px; }
.sync-badge { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); font-size: 13px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); } .dot.err { background: var(--err); } .dot.off { background: var(--line2); }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 0 12px; height: 40px; text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; background: var(--head); white-space: nowrap; }
td { padding: 0 12px; height: 46px; border-top: 1px solid var(--line); font-size: 13px; vertical-align: middle; white-space: nowrap; }
td.num, th.num { text-align: right; }
td.mono, .mono { font-family: var(--mono); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
tr.dim td { color: var(--muted); }
tr.row-link { cursor: pointer; } tr.row-link:hover td { background: #FBFAF6; }
td a.rowa { color: inherit; text-decoration: none; }
.any { color: var(--muted); font-style: italic; }
.warn-tag { color: var(--warn); font-size: 11px; font-weight: 600; margin-left: 6px; }
.table-foot { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-top: 1px solid var(--line); gap: 12px; flex-wrap: wrap; }
.empty { padding: 48px 24px; text-align: center; color: var(--muted); }

/* notices */
.notice { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: 10px; }
.notice.ok { background: var(--ok-bg); color: var(--ok); } .notice.err { background: var(--err-bg); color: var(--err); }
.notice.warn { background: var(--warn-bg); color: var(--warn); } .notice.info { background: var(--accent-bg); color: var(--accent); }
.reveal { display: flex; flex-direction: column; gap: 12px; padding: 20px 24px; border-radius: 12px; background: var(--ok-bg); color: var(--ok); }
.reveal code { flex-grow: 1; min-height: 40px; display: flex; align-items: center; padding: 0 14px; border-radius: 8px; background: var(--surface); color: var(--ink); font-family: var(--mono); font-size: 13px; word-break: break-all; }
.codeblock { display: block; padding: 14px 16px; border-radius: 8px; background: var(--side); color: #E6E8EC; font-family: var(--mono); font-size: 13px; line-height: 1.6; overflow-x: auto; white-space: pre; }

/* settings */
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs a { padding: 12px 4px; margin-right: 20px; color: var(--muted); font-weight: 500; text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a[aria-current="page"] { color: var(--ink); font-weight: 600; border-bottom-color: var(--accent); }
.split { display: flex; gap: 24px; align-items: flex-start; flex-wrap: wrap; }
.split > .grow { flex: 1 1 560px; min-width: 0; }
.split > .aside { flex: 0 0 360px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }

/* shops inline edit */
.cell-input { height: 34px; width: 100%; min-width: 160px; border: 1px solid var(--line); border-radius: 6px; padding: 0 10px; background: var(--surface); font: inherit; font-size: 13px; }
.cell-input:placeholder-shown { border-color: var(--line2); }

/* detail */
.kv { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 20px 24px; }
.kv div span { display: block; font-size: 12px; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; margin-bottom: 4px; }
.kv div strong { font-weight: 500; }

/* login */
.login { display: flex; min-height: 100vh; }
.login-side { width: 40%; max-width: 560px; background: var(--side); padding: 48px; display: flex; flex-direction: column; justify-content: space-between; color: #fff; }
.login-side .tag { font-family: var(--serif); font-size: 56px; line-height: 1.05; }
.login-main { flex-grow: 1; display: flex; align-items: center; justify-content: center; padding: 32px; }
.login-form { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 20px; }

@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .side { width: auto; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 4px; }
  .side-label, .side-foot .who { display: none; }
  .side-foot { margin: 0 0 0 auto; border: 0; padding: 0; }
  main { padding: 20px 16px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kv, .grid2 { grid-template-columns: 1fr; }
  .login-side { display: none; }
}

/* sortable headers */
th a.sort { color: inherit; text-decoration: none; display: inline-flex; align-items: center; gap: 4px; }
th a.sort:hover, th a.sort.on { color: var(--ink); }
.sort-ind { font-size: 10px; opacity: .45; }
th a.sort.on .sort-ind { opacity: 1; color: var(--accent); }
th.num a.sort { flex-direction: row-reverse; }

/* table toolbar + pickers (Sort, Columns) */
.table-tools { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: -8px; }
.sort-summary { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 13px; }
.picker { position: relative; }
.picker > summary { list-style: none; }
.picker > summary::-webkit-details-marker { display: none; }
.picker-panel { position: absolute; right: 0; top: 48px; z-index: 20; width: 420px; max-width: calc(100vw - 32px); padding: 16px; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 12px 32px rgba(20, 23, 28, .14); }
.picker-head { display: flex; flex-direction: column; gap: 2px; }
.picker-list { list-style: none; margin: 0; padding: 0; max-height: 52vh; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; }
.picker-list li { display: flex; align-items: center; gap: 8px; padding: 4px 8px; border-top: 1px solid var(--line); background: var(--surface); }
.picker-list li:first-child { border-top: 0; }
.picker-list li.dragging { opacity: .4; }
.picker-list li.drop-before { box-shadow: inset 0 2px 0 var(--accent); }
.picker-list li.drop-after { box-shadow: inset 0 -2px 0 var(--accent); }
.picker-list li .check { flex-grow: 1; min-height: 32px; }
.picker-list .grip { cursor: grab; color: var(--muted); letter-spacing: -2px; user-select: none; }
.picker-move { display: flex; }
.picker-move .btn-text { width: 28px; padding: 0; font-size: 15px; }
.picker-foot { justify-content: flex-end; }
.sort-list li { padding: 8px; }
.sort-list select.input { height: 36px; }
.sort-list select[name="sort_key"] { flex-grow: 1; min-width: 0; }
.sort-list .level-no { width: 18px; color: var(--muted); font-family: var(--mono); font-size: 12px; }
#sort-add { align-self: flex-start; }

/* resizable columns */
table.resizable th { position: relative; }
table.resizable.fixed { table-layout: fixed; }
table.resizable.fixed td { overflow: hidden; text-overflow: ellipsis; }
table.resizable.fixed th { overflow: hidden; text-overflow: ellipsis; }
.col-resize { position: absolute; top: 0; right: 0; width: 9px; height: 100%; cursor: col-resize; z-index: 1; touch-action: none; }
.col-resize::after { content: ""; position: absolute; top: 10px; bottom: 10px; right: 3px; width: 2px; border-radius: 1px; background: transparent; }
th:hover .col-resize::after { background: var(--line2); }
.col-resize:hover::after, .col-resize:focus-visible::after, .col-resize.active::after { background: var(--accent); }
body.col-resizing { cursor: col-resize; user-select: none; }

/* filter panel */
.tools-summary { display: flex; flex-direction: column; gap: 6px; }
.filter-chip { font-family: var(--sans); max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; line-height: 22px; }
.filter-chip strong { color: var(--accent); margin: 0 2px; }
.filter-panel { width: 560px; }
.filter-list li.filter-row { flex-direction: column; align-items: stretch; gap: 8px; padding: 10px; }
.filter-top { display: flex; gap: 8px; align-items: center; }
.filter-top select.input { height: 36px; }
.filter-top select.input:first-child { flex-grow: 1; min-width: 0; }
.filter-top select.op { width: 72px; }
.vpick-btn { height: 36px; justify-content: flex-start; font-weight: 400; overflow: hidden; text-overflow: ellipsis; }
.vpick-btn.empty { color: var(--muted); border-style: dashed; }
.vpick-pop { display: flex; flex-direction: column; gap: 8px; border: 1px solid var(--line); border-radius: 8px; padding: 8px; background: var(--head); }
.vpick-pop[hidden] { display: none; }
.vpick-pop .input { height: 34px; }
.vpick-list { max-height: 240px; overflow-y: auto; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 4px 0; }
.vpick-item { display: flex; align-items: center; gap: 8px; padding: 4px 10px; min-height: 32px; cursor: pointer; }
.vpick-item:hover { background: var(--head); }
.vpick-item[hidden] { display: none; }
.vpick-item.is-null .vpick-label { font-family: var(--mono); font-size: 12px; color: var(--warn); }
.vpick-label { flex-grow: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vpick-foot { display: flex; align-items: center; gap: 4px; }
.vpick-foot .hint { flex-grow: 1; }
