/* 弹窗外观与遮罩由 CSS 控制；焦点、键盘、滚动锁由 modal.js 处理。 */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
}

.modal[hidden] {
  display: none;
}

.modal--filter {
  background: rgba(0, 0, 0, 0.65);
}

.modal--overlay {
  z-index: 1100;
}

.modal__dialog {
  display: flex;
  flex-direction: column;
  max-width: calc(100vw - calc(32px * var(--ui-scale)));
  max-height: calc(100vh - calc(32px * var(--ui-scale)));
  background: var(--color-surface);
  border: 0;
  box-shadow: inset 0 0 0 calc(1px * var(--ui-scale)) var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.modal__dialog--sm {
  width: calc(280px * var(--ui-scale));
}

.modal__dialog--md {
  width: calc(360px * var(--ui-scale));
}

.modal__dialog--help {
  width: calc(420px * var(--ui-scale));
}

.modal__dialog--filter {
  width: calc(512px * var(--ui-scale));
}

.modal__dialog--calc {
  width: calc(380px * var(--ui-scale));
  height: calc(260px * var(--ui-scale));
}

/* 计算器弹窗使用紧凑头部。 */
.modal__dialog--calc .modal__header {
  align-items: center;
  height: calc(38px * var(--ui-scale));
  padding: 0 calc(16px * var(--ui-scale));
}

/* 计算器弹窗底部操作区与内容保持间距。 */
.modal__dialog--calc .modal__footer {
  padding: calc(20px * var(--ui-scale)) calc(16px * var(--ui-scale)) calc(20px * var(--ui-scale));
}

/* 标题和关闭按钮在头部垂直对齐。 */
.modal__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  height: calc(48px * var(--ui-scale));
  flex: 0 0 auto;
  padding: calc(11px * var(--ui-scale)) calc(16px * var(--ui-scale)) 0;
}

.modal__title {
  color: var(--color-text);
  font-size: var(--font-11);
  font-weight: 600;
  letter-spacing: 0.022em;
  line-height: calc(16px * var(--ui-scale));
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal__close {
  flex: 0 0 auto;
  width: calc(16px * var(--ui-scale));
  height: calc(16px * var(--ui-scale));
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--color-text);
  opacity: 0.4;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal__close:hover {
  opacity: 0.7;
}

.modal__close svg {
  display: block;
  width: 100%;
  height: 100%;
}

.modal__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 0 calc(16px * var(--ui-scale));
}

/* 底部操作按钮靠右排列。 */
.modal__footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: calc(12px * var(--ui-scale));
  flex: 0 0 auto;
  padding: calc(20px * var(--ui-scale)) calc(16px * var(--ui-scale)) calc(24px * var(--ui-scale));
}

.modal__action {
  width: calc(72px * var(--ui-scale));
  height: calc(28px * var(--ui-scale));
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--color-primary);
  color: #121212;
  font-size: var(--font-10);
  font-weight: 600;
  letter-spacing: 0.022em;
  cursor: pointer;
  padding: 0;
}

.modal__action--wide {
  width: calc(76px * var(--ui-scale));
}

/* 重置和取消操作采用次级按钮样式。 */
.modal__action--secondary {
  width: calc(60px * var(--ui-scale));
  background: var(--color-surface-alt);
  box-shadow: inset 0 0 0 calc(1px * var(--ui-scale)) var(--color-border);
  color: var(--color-text);
  opacity: 0.8;
  font-weight: 400;
}

.modal__action--secondary:hover {
  opacity: 1;
}

.modal__action--reset {
  margin-right: auto;
  background: rgba(255, 213, 108, 0.15);
  box-shadow: inset 0 0 0 calc(1px * var(--ui-scale)) rgba(255, 213, 108, 0.25);
  color: #ffd56c;
}

.modal__action--reset:hover {
  background: rgba(255, 213, 108, 0.25);
}

.modal--dark {
  background: rgba(0, 0, 0, 0.65);
}

.modal__dialog--lg {
  width: calc(512px * var(--ui-scale));
}

/* 页签弹窗沿用标题行高；过小的行高会裁掉中文字符顶部。 */
.modal__dialog--tabbed .modal__header {
  align-items: center;
  height: calc(38px * var(--ui-scale));
  padding: 0 calc(16px * var(--ui-scale));
}

/* 页签行左右留白，并为分割线保留空间。 */
.modal__tabs {
  position: relative;
  display: flex;
  gap: calc(24px * var(--ui-scale));
  height: calc(26px * var(--ui-scale));
  flex: 0 0 auto;
  padding: 0 calc(24px * var(--ui-scale));
}

/* 分割线独立于页签盒定位，并由脚本对齐物理像素以保持线宽一致。 */
.modal__tabs-divider {
  position: absolute;
  left: calc(24px * var(--ui-scale));
  right: calc(24px * var(--ui-scale));
  bottom: 0;
  height: calc(1px * var(--ui-scale));
  background: var(--color-border);
  pointer-events: none;
}

/* 页签按钮保留最小点击宽度；激活态使用主题色。 */
.modal__tab {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  min-width: calc(40px * var(--ui-scale));
  border: 0;
  padding: 0 0 calc(5px * var(--ui-scale));
  background: transparent;
  color: rgba(255, 255, 255, 0.52);
  font-size: var(--font-10);
  font-weight: 400;
  letter-spacing: 0.022em;
  line-height: 1;
  cursor: pointer;
  position: relative;
}

.modal__tab[hidden] {
  display: none;
}

.modal__tab--active {
  color: var(--color-primary);
  font-weight: 600;
}

/* 激活下划线随页签宽度变化，并覆盖分割线以保持连续。 */
.modal__tab--active::after {
  content: "";
  position: absolute;
  z-index: 1;
  left: 50%;
  bottom: calc(-1px * var(--ui-scale));
  transform: translateX(-50%);
  width: 100%;
  height: calc(2px * var(--ui-scale));
  border-radius: calc(1px * var(--ui-scale));
  background: var(--color-primary);
}

.modal__dialog--tabbed .modal__body {
  padding: calc(16px * var(--ui-scale)) calc(24px * var(--ui-scale)) calc(20px * var(--ui-scale));
}

.modal__panel {
  display: none;
}

.modal__panel--active {
  display: flex;
  flex-direction: column;
  gap: calc(12px * var(--ui-scale));
}

/* 底部布局：--split 左（删除/添加）右（取消/确定）两段；按钮组内距 8，取消-确定距 16 */
.modal__footer--split {
  justify-content: space-between;
  padding: 0 calc(24px * var(--ui-scale)) calc(24px * var(--ui-scale));
}

.modal__footer-group {
  display: flex;
  align-items: center;
  gap: calc(8px * var(--ui-scale));
}

.modal__footer-group--actions {
  gap: calc(16px * var(--ui-scale));
}

.modal__action--neutral {
  background: var(--color-surface-alt);
  box-shadow: inset 0 0 0 calc(1px * var(--ui-scale)) rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.8);
}

.modal__action--neutral:hover {
  color: var(--color-text);
}

.modal__action--danger {
  background: rgba(255, 119, 119, 0.1);
  box-shadow: inset 0 0 0 calc(1px * var(--ui-scale)) rgba(255, 119, 119, 0.24);
  color: #ff7777;
}

.modal__action--ghost {
  background: rgba(180, 160, 251, 0.12);
  box-shadow: inset 0 0 0 calc(1px * var(--ui-scale)) rgba(180, 160, 251, 0.3);
  color: var(--color-primary);
}

.modal__action[hidden] {
  display: none;
}

/* 同款兜底：分组容器 display:flex 同样会压过 UA 的 [hidden]——
   split 底部左侧「删除」组（添加态 hidden、编辑态显示）依赖此规则生效 */
.modal__footer-group[hidden] {
  display: none;
}

.modal__dialog--filter .modal__header {
  height: calc(44px * var(--ui-scale));
}

.modal__dialog--filter .modal__footer {
  padding-top: calc(18px * var(--ui-scale));
  padding-bottom: calc(20px * var(--ui-scale));
}

.modal__dialog--filter-tall .modal__footer {
  padding-top: calc(24px * var(--ui-scale));
}

/* 筛选字段按两列排列，更多条件自动换行。 */
.filter-fields {
  display: grid;
  grid-template-columns: repeat(2, calc(228px * var(--ui-scale)));
  justify-content: space-between;
  row-gap: calc(12px * var(--ui-scale));
}

/* 弹窗标签保留足够行高，避免中文笔画被下方定位控件遮盖。 */
.filter-field {
  display: grid;
  gap: calc(6px * var(--ui-scale));
}

.filter-field .form-label {
  line-height: calc(12px * var(--ui-scale));
}
