/* 落ち着いた灰色を基本にし、色はシートの種類を示す小さな点だけに使う */
:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --subtle: #f4f4f5;
  --border: #e4e4e7;
  --border-strong: #d4d4d8;
  --text: #18181b;
  --text-2: #3f3f46;
  --muted: #71717a;
  --faint: #a1a1aa;
  --primary: #18181b;
  --primary-hover: #27272a;
  --ring: rgba(24, 24, 27, 0.12);
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warning-bg: #fffbeb;
  --warning-border: #fde68a;
  --warning-text: #92400e;
  --ok: #16a34a;
  --dot-共通: #a1a1aa;
  --dot-大分類: #8b5cf6;
  --dot-グループ: #0ea5e9;
  --dot-商品: #10b981;
  --dot-未使用: #f59e0b;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 24px 48px -12px rgba(0, 0, 0, 0.18), 0 0 0 1px rgba(0, 0, 0, 0.04);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.65 Inter, "Noto Sans JP", -apple-system, BlinkMacSystemFont, "Hiragino Sans", sans-serif;
  -webkit-font-smoothing: antialiased;
  letter-spacing: 0.01em;
}
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

/* ---------------------------------------------------------------- 上のバー */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 24px;
  height: 56px;
  padding: 0 24px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo { width: 22px; height: 22px; border-radius: 6px; background: var(--primary); position: relative; }
.logo::after { content: ""; position: absolute; inset: 6px 5px; border: 2px solid #fff; border-top: 0; border-radius: 0 0 6px 6px; }
.brand-title { font-weight: 600; font-size: 15px; }
.brand-client {
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 8px;
}
.brand-client:empty { display: none; }
.tabs { display: flex; gap: 2px; height: 100%; }
.tab {
  position: relative;
  border: 0;
  background: none;
  padding: 0 12px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 500;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--text); }
.tab.is-active::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: -1px; height: 2px; background: var(--text); border-radius: 2px; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.mode { display: flex; align-items: center; gap: 10px; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); white-space: nowrap; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--warning-text); }
.status.is-web::before { background: var(--ok); }
.user { font-size: 12px; color: var(--muted); }

.notice {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 24px 0;
  padding: 10px 14px;
  border: 1px solid var(--warning-border);
  border-radius: var(--radius);
  background: var(--warning-bg);
  color: var(--warning-text);
  font-size: 13px;
}
.notice.error { border-color: #fecaca; background: var(--danger-soft); color: var(--danger); }

/* ---------------------------------------------------------------- 配置 */
.layout { display: grid; grid-template-columns: 272px minmax(0, 1fr); gap: 24px; padding: 20px 24px 48px; align-items: start; }
.single { padding: 24px 24px 48px; max-width: 1200px; }

.sidebar { position: sticky; top: 76px; max-height: calc(100vh - 96px); overflow: auto; padding-right: 4px; }
.sidebar-section { padding: 2px 2px 12px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.sheet-group-title { font-size: 11px; font-weight: 600; color: var(--faint); margin: 14px 10px 4px; text-transform: uppercase; letter-spacing: 0.06em; }
.sheet-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 10px;
  border: 0;
  border-radius: 6px;
  background: none;
  cursor: pointer;
  text-align: left;
  color: var(--text-2);
}
.sheet-item:hover { background: var(--subtle); color: var(--text); }
.sheet-item.is-active { background: var(--surface); color: var(--text); font-weight: 500; box-shadow: var(--shadow-sm), 0 0 0 1px var(--border); }
.sheet-item .order { color: var(--faint); font-size: 12px; width: 14px; text-align: right; }
.sheet-item .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-item .count { font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; }
.sheet-item.is-special { color: var(--text); font-weight: 500; }

.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--dot, var(--faint)); flex-shrink: 0; }
.k-共通 { --dot: var(--dot-共通); }
.k-大分類 { --dot: var(--dot-大分類); }
.k-グループ { --dot: var(--dot-グループ); }
.k-商品 { --dot: var(--dot-商品); }
.k-未使用 { --dot: var(--dot-未使用); }
.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 8px;
  background: var(--surface);
  white-space: nowrap;
}
.tag::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--dot, var(--faint)); }

/* ---------------------------------------------------------------- 見出し・操作 */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 16px; }
.page-title { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: -0.01em; display: flex; align-items: center; gap: 10px; }
.page-desc { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.search { position: relative; flex: 1 1 260px; max-width: 360px; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--faint); }
.search input { width: 100%; height: 34px; padding: 0 10px 0 32px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.segmented { display: inline-flex; padding: 2px; background: var(--subtle); border-radius: var(--radius); }
.segmented button { border: 0; background: none; padding: 4px 10px; border-radius: 6px; cursor: pointer; color: var(--muted); font-size: 13px; display: inline-flex; align-items: center; gap: 6px; }
.segmented button.is-on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.result-count { margin-left: auto; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

.label { display: flex; align-items: baseline; gap: 8px; font-size: 12px; font-weight: 600; color: var(--text-2); margin: 16px 0 6px; }
.label:first-child { margin-top: 0; }
.label-note { font-weight: 400; color: var(--faint); }
.hint { color: var(--muted); font-size: 12px; margin: 8px 2px 0; }
.input, .select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  background: var(--surface);
  transition: border-color 0.12s, box-shadow 0.12s;
}
.select { height: 34px; padding: 0 30px 0 10px; appearance: none; background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%2371717a' stroke-width='1.6'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E") no-repeat right 8px center / 14px; }
.select-inline { width: auto; min-width: 150px; }
.textarea { resize: vertical; line-height: 1.7; }
.input:focus, .select:focus, .search input:focus { outline: 0; border-color: var(--border-strong); box-shadow: 0 0 0 3px var(--ring); }
.input:disabled, .select:disabled { background: var(--subtle); color: var(--text-2); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: var(--subtle); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger-ghost { border-color: transparent; color: var(--danger); background: none; }
.btn-danger-ghost:hover { background: var(--danger-soft); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.icon-btn { border: 0; background: none; width: 30px; height: 30px; border-radius: 6px; display: grid; place-items: center; color: var(--muted); cursor: pointer; }
.icon-btn:hover { background: var(--subtle); color: var(--text); }

/* ---------------------------------------------------------------- ナレッジの一覧 */
.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.row {
  display: block;
  width: 100%;
  padding: 14px 16px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: none;
  text-align: left;
  cursor: pointer;
}
.row:last-child { border-bottom: 0; }
.row:hover { background: #fcfcfd; }
.row:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; }
.row-head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.row-title { flex: 1; min-width: 0; font-weight: 600; color: var(--text); }
.row-meta { display: flex; align-items: center; gap: 8px; color: var(--faint); font-size: 12px; }
.row-body {
  color: var(--muted);
  font-size: 13px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.row.is-overridden { background: var(--bg); }
.row.is-overridden .row-title, .row.is-overridden .row-body { color: var(--faint); }
.row-note { font-size: 12px; color: var(--warning-text); margin-top: 6px; }
.badge { font-size: 11px; font-weight: 500; color: var(--warning-text); background: var(--warning-bg); border: 1px solid var(--warning-border); border-radius: 999px; padding: 0 7px; }
mark { background: #fef08a; color: inherit; border-radius: 2px; padding: 0 1px; }

.empty { padding: 48px 16px; text-align: center; color: var(--muted); font-size: 13px; }
.empty strong { display: block; color: var(--text); font-weight: 600; margin-bottom: 4px; font-size: 14px; }

/* ---------------------------------------------------------------- 商品の表 */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { position: sticky; top: 0; background: var(--bg); font-size: 12px; font-weight: 500; color: var(--muted); text-align: left; padding: 9px 16px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover td { background: #fcfcfd; }
.table tr:last-child td { border-bottom: 0; }
.table .alias { white-space: pre-line; color: var(--muted); font-size: 13px; }
.table .num { font-variant-numeric: tabular-nums; color: var(--text-2); }
.table .product-name { font-weight: 600; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; }
.none { color: var(--faint); }

/* ---------------------------------------------------------------- ポップアップ */
.dialog {
  border: 0;
  padding: 0;
  border-radius: var(--radius-lg);
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  box-shadow: var(--shadow-lg);
  color: var(--text);
}
.dialog-wide { width: min(760px, calc(100vw - 32px)); }
.dialog[open] { animation: pop 0.14s ease-out; }
.dialog::backdrop { background: rgba(9, 9, 11, 0.45); backdrop-filter: blur(2px); }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(0.99); } to { opacity: 1; transform: none; } }
.dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 48px); }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 20px 24px 12px; }
.dialog-title { margin: 0; font-size: 17px; font-weight: 600; }
.dialog-desc { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.dialog-body { padding: 4px 24px 8px; overflow: auto; }
.dialog-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 24px; border-top: 1px solid var(--border); background: var(--bg); }
.dialog-foot-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.form-error { color: var(--danger); font-size: 13px; margin: 12px 0 0; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 12px;
  background: var(--surface);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-2);
}
.chip:hover { border-color: var(--border-strong); }
.chip.is-on { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip.is-on { cursor: default; padding-right: 4px; }
.chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: inherit;
  opacity: 0.7;
  cursor: pointer;
}
.chip-remove:hover { opacity: 1; background: rgba(255, 255, 255, 0.18); }
.chip-remove svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.chips:not(:empty) + .combo { margin-top: 10px; }
.combo-menu {
  position: fixed;
  z-index: 10;
  max-height: 208px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 12px 28px -8px rgba(0, 0, 0, 0.18), 0 0 0 1px rgba(0, 0, 0, 0.02);
  padding: 4px;
}
.combo-option {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 0;
  border-radius: 6px;
  background: none;
  padding: 7px 10px;
  text-align: left;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}
.combo-option.is-active { background: var(--subtle); }
.combo-option .combo-count { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.combo-option.is-new { color: var(--text-2); }
.combo-option.is-new svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.combo-empty { padding: 8px 10px; color: var(--muted); font-size: 12px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--primary);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  z-index: 20;
  animation: pop 0.14s ease-out;
}

/* ---------------------------------------------------------------- ログイン */
body.is-login .tabs, body.is-login .topbar-right { display: none; }
.login { min-height: calc(100vh - 56px); display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 32px 28px; box-shadow: var(--shadow-sm); }
.logo-lg { display: block; width: 36px; height: 36px; border-radius: 9px; margin-bottom: 16px; }
.logo-lg::after { inset: 10px 9px; border-width: 3px; border-radius: 0 0 9px 9px; }
.login-title { margin: 0; font-size: 18px; font-weight: 600; }
.login-desc { margin: 6px 0 20px; color: var(--muted); font-size: 13px; }
.btn-block { width: 100%; margin-top: 16px; height: 38px; }

@media (max-width: 900px) {
  .topbar { height: auto; flex-wrap: wrap; gap: 8px 16px; padding: 10px 16px 0; }
  .topbar-right { margin-left: 0; width: 100%; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
  .tabs { order: 3; width: 100%; height: 40px; overflow-x: auto; }
  .tab.is-active::after { bottom: 0; }
  .user { display: none; }
  .layout { grid-template-columns: 1fr; padding: 16px; }
  .sidebar { position: static; max-height: none; }
  .single { padding: 16px; }
  .notice { margin: 12px 16px 0; }
  .page-head { flex-direction: column; }
}
